我可以在CompositionTarget.Rendering内部做什么? [英] What can I do inside CompositionTarget.Rendering?

查看:111
本文介绍了我可以在CompositionTarget.Rendering内部做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CompositionTarget.Rendering 事件是构建游戏主循环的完美之选.它基本上以vsync(通常为60 Hz)的速率触发.

The CompositionTarget.Rendering event is the perfect thing to build a game's main loop upon. It basically fires at the rate of vsync (usually 60 Hz).

恰好在之前出现.在将动画和布局应用于合成树后,将渲染"事件路由到指定的事件处理程序.

Occurs just before the objects in the composition tree are rendered. The Rendering event is routed to the specified event handler after animation and layout have been applied to the composition tree.

每帧动画的使用方法文章做了一些解释多一点.

The per-frame animation how-to article explains a little bit more.

请注意,在计算布局之后,将调用事件处理程序方法.但是,您可以在事件处理程序方法中修改布局,这意味着在渲染之前将再次计算布局.

Note that your event handler method is called after layout has been computed. However, you can modify layout in your event handler method, which means that layout will be computed once more before rendering.

基于此,其处理程序中的代码规则为:

Based on that, the rules for code inside its handler are:

  • 避免更改布局
  • 快速返回

还有其他陷阱吗?哪些非显而易见的动作导致另一次布局过关?我在处理程序中到底有多少时间?

What other gotchas are there? What non-obvious actions cause another layout pass? How much time exactly do I have inside the handler?

推荐答案

我认为它的主要目的是启用无计时器的动画,例如那些需要像常规重力一样使用物理元素的动画.但是,它不是游戏图形的好地方... WPF 不是一种游戏语言,严肃的游戏将使用该语言可以顺利运行有太多的开销.如果要编写.NET游戏,请使用 XNA .

I think the main purpose of it is to enable timer-free animations, such as those employing physics element like gravity, where exact regular timing is required. However it is not a good place for gaming graphics... WPF is not a gaming language and serious games will not run smoothly using it as there is too much overhead. If you want to write a .NET game, then use XNA.

摘自《 WPF控件开发的释放:建立高级用户体验》一书:

From the book 'WPF Control Development Unleashed: Building Advanced User Experiences':

一些读者可能会认识到这种方法与高端图形之间的相似之处子系统,例如DirectX.不要将CompositionTarget.Rendering误认为是良好的注入指向创建基于WPF的游戏图形引擎.高端显卡和超高帧频并不是WPF动画这一特定方面的目标.

Some readers may recognize a similarity between this approach and higher-end graphics subsystems like DirectX. Do not mistake CompositionTarget.Rendering for a good injection point to create a WPF-based gaming graphics engine. High-end graphics and ultrahigh frame rates are not the goal of this particular aspect of WPF animation.

类似于DispatcherTimer方法,基于CompositionTarget.Rendering的动画也没有时间限制.但是,这些事件与渲染线程同步,导致比DispatcherTimer更流畅的动画.也没有必要开始和停止计时器,尽管您可能必须分离并附加事件处理程序以进行改进性能.

Similar to the DispatcherTimer approach, animations based on CompositionTarget.Rendering are also not time-bound. However, these events are synced with the render thread resulting in smoother animations than the DispatcherTimer. Also there is no need to start and stop a timer, although you may have to detach and attach the event handler to improve performance.

这篇关于我可以在CompositionTarget.Rendering内部做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆