当两个图像碰撞时如何生成片尾画面?
当两个图像碰撞时如何生成片尾画面。我正在制作一个带有火柴人的应用程序,你可以使用非常灵敏的加速度计来移动。因此,如果它达到这些峰值,(UIImages)它将生成最终屏幕。如何让应用程序检测到这种碰撞,然后生成结束屏幕。
how to generate an end screen when two images collide. I am making an app with a stickman you move with a very sensitive acceremeter. SO if it hits these spikes, (UIImages) it will generate the end screen. How do I make the app detect this collision and then generate an end screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确信您知道两个图像的矩形,因为您需要绘制它们,以便您可以使用
如果两个矩形有共享点,它会返回 YES
I'm sure you know the rect of the two images because you need to draw them so you can use
It returns YES if the two rects have a shared point
您尚未声明任何 rects 的事实并不重要。您需要矩形来进行碰撞检测。我假设您至少有火柴人的 x 和 y 坐标,并且您应该对他的高度和宽度有某种了解。从问题标题来看,您似乎正在使用图像来绘制要检查碰撞的对象,因此您应该知道您正在使用的图像的高度和宽度。如果您没有此信息,您将无法在正确的位置绘制对象,并且您当然无法检查碰撞。
您基本上想要使用与绘制对象相同的矩形。
一些代码示例:
如果您的坐标指向火柴人的中间,您将使用如下所示的内容:
如果您的坐标指向火柴人的左上角,您将使用:
如果我可以给您一个建议,我建议将坐标和大小存储在 CGRect 中,这样您就不必每次检查碰撞时都创建一个新的 CGRect。
The fact that you haven't declared any rects doesn't matter. You need rects for collision detection. I assume that you at least have x and y coordinates for the stickman and you should have some kind of idea of his height and width. Judging from the question title it seems like you're using images to draw the objects you want to check for collision, so you should know the height and width of the images you're using. If you don't have this info you can't draw the objects in the right place and you certainly can't check for collisions.
You basically want to use the same rects that you use for drawing the objects.
Some code examples:
If your coordinates point to the middle of the stickman you would use something like the following:
If your coordinates point to the top left corner of your stickman you would use:
If I might give you a suggestion, I would suggest storing the coordinates and sizes in a CGRect, so that you don't have to create a new CGRect every time you're checking for collision.