控件位于不同画布/图层时的 Silverlight 碰撞检测
对于我们的游戏,我们必须创建碰撞检测。 问题在于碰撞对象位于不同的画布/图层中,这使得通过点定位进行碰撞检测变得不可能。
有谁知道如何解决这个问题?
For our game we have to create collision detection.
The problem is that the collided objects are in different canvasses/layers, which makes collision detection by pointlocation inpossible.
Does anyone have an idea how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有更多信息,很难给出很好的答案,但如果所有层的大小相同,那么您可以进行自己的碰撞检测。您需要知道的只是要检测碰撞的两个物体的位置和大小。然后您只需测试一个矩形是否与另一个矩形相交。
还有一个可能有用的函数,称为 TranslatePoint。这会将一个 UIElements 坐标转换为另一个坐标。因此,如果你有一个球在屏幕的较小区域内弹跳,并且具有自己的局部坐标系,则可以使用此函数获取球相对于整个屏幕的坐标。
It's hard to give a great answer without some more information, but if all your layers are the same size then you can just roll your own collision detection. All you need to know is the locations and sizes of two things to be collision detected. Then you just test to see if one rectangle intersects with the other rectangle.
There is also a function that might be useful to use called TranslatePoint. This translates from one UIElements coordinates to another. So if you had a ball bouncing around in a smaller area of the screen with it's own local coordinate system, you could get the ball's coordinates relative to the entire screen with this function.
我可以建议你尝试使用 Farseer 物理引擎来减轻自己的痛苦吗?
http://farseerphysicals.codeplex.com/
它非常好,已经在一些 WP7 游戏中使用。
http://www.farseergames.com/
还有一些 Blend 行为和帮助程序,使其使用起来更加容易:
http://physicalshelper.codeplex.com/
Can I suggest you try using the Farseer physics engine just to save yourself some pain?
http://farseerphysics.codeplex.com/
It's very good and is in use in some WP7 games already.
http://www.farseergames.com/
There's also some Blend behaviors and helpers to make using it even easier:
http://physicshelper.codeplex.com/