gpt4 book ai didi

wpf - 我可以在 CompositionTarget.Rendering 中做什么?

转载 作者:行者123 更新时间:2023-12-04 14:44:58 30 4
gpt4 key购买 nike

CompositionTarget.Rendering event 是构建游戏主循环的完美选择。它基本上以 vsync 的速率(通常为 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.



per-frame animation how-to文章解释了一点。

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.



基于此,其处理程序内的代码规则是:
  • 避免改变布局
  • 快回来

  • 还有什么其他问题? 哪些不明显的操作会导致另一个布局通过?我在处理程序中有多少时间?

    最佳答案

    我认为它的主要目的是启用无计时器动画,例如那些使用重力等物理元素的动画,需要精确的规则计时。然而它是不是 游戏图形的好地方... WPF 是 不是 一种游戏语言和严肃的游戏会不是 使用它可以顺利运行,因为开销太大。如果你想写一个 .NET 游戏,那么使用 XNA .

    来自《WPF Control Development Unleashed: Building Advanced User Experiences》一书:

    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.

    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.

    关于wpf - 我可以在 CompositionTarget.Rendering 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18353225/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com