对于我的游戏主循环我应该考虑什么:DispatcherTimer Vs StoryBoard

发布于 2024-08-04 23:47:31 字数 546 浏览 2 评论 0原文

我正在编写一个游戏,我想在游戏主循环中启动一个事件,该事件必须在很短的时间间隔后触发。

DispatcherTimer 帮助我实现了这一点,我发现了这篇文章

http://blogs.silverlight.net/blogs/msnow/archive/2008/07/09/storyboard-versus-dispatchertimer-for-animation-and-game- Loops.aspx

根据 StoryBoard 方法,它比 DispatcherTimer 更好。这个博客是针对 silverlight 的,我仍在 MSDN 文档中搜索 WPF Storyboard 是否也在第二个线程上启动。有谁知道在 WPF 中使用故事板计时器是否比调度程序计时器有优势。

I am writing a game in which I want to kick off an event for my game main loop, the event has to be fired after a very small interval of time.

DispatcherTimer helped me in implementing that, I came across this article

http://blogs.silverlight.net/blogs/msnow/archive/2008/07/09/storyboard-versus-dispatchertimer-for-animation-and-game-loops.aspx

according to it StoryBoard approach is better then dispatchertimer. This blog is for silverlight, I am still searching in MSDN docs if WPF storyboard is also kicked off on a second thread. Does anyone know if using storyboard timer in WPF has advantages over dispatcher timer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无戏配角 2024-08-11 23:47:31

您还可以尝试使用 CompositionTarget.Rendering 事件,只需远离 StoryBoard 即可。以下是有关 CompositionTarget.Rendering 的几个链接:

如何:按每帧间隔进行渲染使用 CompositionTarget

Silverlight CompositionTarget.Rendering游戏循环

动画乐趣第 1 部分 - CompositionTarget.Rendering

You could also try to use CompositionTarget.Rendering event, just stay away from the StoryBoard. Here are several links about CompositionTarget.Rendering:

How to: Render on a Per Frame Interval Using CompositionTarget

Silverlight CompositionTarget.Rendering Game Loop

Fun With Animation Part 1 - CompositionTarget.Rendering

巷子口的你 2024-08-11 23:47:31

我想说,既然它来自官方博客,那么它可能是正确的,并且优点是该博客文章中列出的。这篇文章是由 Microsoft Web 工具团队的高级 SDET 主管撰写的。所以我不得不假设他所说的是有道理的。

根据我的研究,StoryboardTimer 优于 DispatcherTimer 的原因如下:

  1. StoryBoard 在单独的线程上处理,不受 DispatcherTimer 所在的 UI 线程的影响。
  2. DispatcherTimer 是一个比 Storyboard 类背后的计时器分辨率较低的计时器,这会导致保真度损失。
  3. Storyboard 的执行在不同受支持的操作系统和 Web 浏览器上更加稳定。

I would say that since its coming from an official blog, then it is probably correct, and the advantages are the one's listed in that blog post. That post was written by a Senior SDET Lead on the Web Tools team at Microsoft. So I would have to assume that what he is saying holds merit.

From my research, the reasons the StoryboardTimer is better than the DispatcherTimer is as follows:

  1. The StoryBoard is handled on a separate thread that is not affected by the UI thread which the DispatcherTimer is on.
  2. The DispatcherTimer is a lower resolution timer than the timer behind the Storyboard class, which causes loss in fidelity.
  3. The Storyboard execution is more stable across the different supported OS’s and web browsers.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文