Windows Phone 7,xna,如何更定期地对触摸屏进行采样

发布于 2024-09-14 07:41:23 字数 220 浏览 7 评论 0原文

好吧,显然 xna 游戏只能以 30 fps 运行,这很遗憾,因为我们在 iPhone 上的游戏在 60 fps 下看起来好多了……

无论如何,因为获得有关触摸屏状态信息的唯一方法是获取目前的状态,实际上这意味着您只能以 30 fps 的速度对触摸屏进行采样。

即使我们的游戏必须以 30fps 运行,有没有办法从触摸屏获得更高分辨率的采样?也许通过回调?或者通过访问带有时间戳的触摸事件列表?

ok, so apparently xna games can only run at 30fps, which is a shame, because our game on iphone looked alot better at 60...

at any rate, because the only way you can get information about the touch screen state is to get its current state, effectively this means you can only sample the touch screen at 30 fps.

even if our game has to run at 30fps, is there any way to get higher resolution sampling from the touch screen? maybe through callbacks? or by accessing a list of touch events with time stamps?

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

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

发布评论

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

评论(2

胡渣熟男 2024-09-21 07:41:23

您正在寻找的功能是 TouchPanel.GetState。在 60Hz 下调用该函数很简单。

要获得 60Hz,您可以设置 Game .TargetElapsedTime 为 1/60 秒。这将为您提供每次抽奖的两次更新(根据 Shawn Hargreaves'在此发布)假设您以 30FPS 进行垂直同步。

如果您仍然希望游戏状态更新以 30FPS 运行(仅以 60FPS 进行触摸输入),那么您可以将这些更新放在不同的线程上。在第一次调用 Game.Update 时启动该线程上的更新,并等待第二次调用完成,依此类推。

(您应该注意,通常 XNA 输入必须在主线程上完成(来源)。我认为这适用于电话和触摸输入。)

或者,您可以自己完全替换 Game 类的计时(调用 GraphicsDevice.Present 你自己)。这并不容易做到,但这是可能的。一个好的起点是查看 Reflector 中的 Game 类。

(免责声明:我还没有尝试过任何实际的基于电话的开发,因此可能存在一些我不知道的与电话相关的问题。)

The function you are looking for is TouchPanel.GetState. It is a simple matter of calling this function at 60Hz.

To get 60Hz you could set Game.TargetElapsedTime to 1/60th of a second. This will give you two updates to every one draw (according to Shawn Hargreaves' post here) assuming you are VSyncing at 30FPS.

If you still want your game state updates to run at 30FPS (just doing touch input at 60FPS), then you could put those updates on a different thread. Start an update going on that thread on the first call to Game.Update, and wait for it to finish on the second one, and so on.

(You should note that normally XNA input must be done on the main thread (source). I assume this applies to Phone and to touch input.)

Alternately you could replace the Game class's timing yourself entirely (calling GraphicsDevice.Present yourself). It's not easy to do, but it's possible. A good place to start is to look at the Game class in Reflector.

(Disclaimer: I haven't tried any actual Phone-based development yet, so there may be some Phone-related gotchas I am unaware of.)

瑕疵 2024-09-21 07:41:23

出于性能原因,设置 30fps 的采样率。

即使您可以找到一种更频繁地查询触摸的方法,您仍然无法以更快的速度更新 UI,所以我不确定您会得到什么好处。

在花费太多时间尝试寻找解决方案之前,我会在实际设备上进行测试,看看 30fps 到底有多可接受。

The sampling rate of 30fps is set for performance reasons.

Even if you could find a way to query for touches more frequently you still couldn't update the UI at a faster rate so I'm not sure what benefit you'd get.

Before spending too much time on trying to find a solution I'd test on an actual device to see how acceptable 30fps really is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文