WP7:在 Silverlight 处理时抑制 XNA 触摸输入?
我在 Mango 中有一个 XNA + Silverlight 游戏:主要是 XNA,上面有一些 Silverlight UI。我遇到的问题是,当您按下按钮或与 Silverlight 控件交互时,触摸信息仍然会传递到 XNA 游戏循环。你如何抑制这种情况?
I've got an XNA + Silverlight game in Mango: Mostly XNA with some Silverlight UI on top. The problem I'm having is that when you hit a button or interact with a Silverlight control, the touch information is still passed along to the XNA game loop. How do you suppress this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
写了一个课程来为我进行跟踪。页面加载后(在 Loaded 处理程序中),创建它并为其提供根元素(以便它可以附加到 LayoutUpdated 事件)。注册在游戏过程中可能覆盖游戏表面的任何控件。然后只需调用 TouchesControl 并传入触摸位置即可确定是否应该忽略该点。它缓存控件区域并在布局更新时更新它们。
应该适用于移动、改变大小或折叠/展开的矩形元素。
(编辑)更新了示例以与更改
可见性
的父元素一起使用。Wrote up a class to do the tracking for me. After your page loads (in the Loaded handler), create this and give it the root element (so it can attach to the LayoutUpdated event). Register any controls that might overlay the game surface during play. Then just call TouchesControl and pass in the touch position to find out if you should ignore that point or not. It caches the regions of the controls and updates them when there's a layout update.
Should work for rectangular elements moving, changing size or collapsing/expanding.
(edit) Updated example to work with parent elements changing
Visibility
.由于与 XNA 互操作的工作方式,您将始终获得由 XNA 和 Silverlight 处理的触摸输入 - 在某种程度上,XNA 具有优先权,因此 Silverlight 在此之上起作用。你可以做什么,如果你需要忽略特定的手势位置(例如 Silverlight 按钮所在的位置),你可以检查手势位置:
Due to the way interop with XNA works, you will always get the touch input processed both by XNA and Silverlight - to some extent, XNA gets the priority, so the Silverlight acts on top of that. What you could do, if you need to ignore specific gesture locations (e.g. where Silverlight buttons are located), you could check the gesture position: