我可以在CompositionTarget

我可以在CompositionTarget

本文介绍了我可以在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).

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

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

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

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':

类似于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内部做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:02