从碰撞的物体获取数据
我目前正在使用 Cocos2d 设计一款游戏。目前还没有代码,因为我仍在发展我的想法。但是,我遇到了一个无法回答的问题,想知道我是否遗漏了某些内容或什么?这就是我目前的想法:
我从屏幕顶部“放下”多个块,它们以随机方向向下移动到屏幕上。它们最终会落在屏幕底部,并将一个堆叠在另一个之上。最终,在坠落时,一些方块会与其他方块发生碰撞。当两个块碰撞时,我想测试每个块的某些特征是否相同(例如大小、颜色、方向等)。每个块都是它自己的对象,将处理它自己的移动和碰撞检测,并且将具有大小、颜色、方向等的访问器方法。
这是我的问题:
我是否正确地认为每个块本身就是一个单独的单元并且不不知道其他街区的情况吗?例如,A块与B块相撞,只知道它与某个东西相撞,但不知道它是另一个块?如果是这样,那么我该如何进行适当的比较呢?如何判断哪个块与哪个块发生了碰撞并访问每个块的数据以及在哪里进行比较?在层中?
我很乐意在这里指出一个正确的方向。我不确定我想做的事情是否可行?有什么建议吗?
I'm currently designing a game using Cocos2d. There's no code yet, as I'm still developing my ideas. But, I've run across a question I can't answer and want to know if I'm just missing something or what? Here's what I'm currently thinking:
I am "dropping" multiple blocks from the top of the screen and they move down the screen in random directions. They will eventually settle at the bottom of the screen and stack up one on top of the other. Eventually, while falling, some blocks are going to collide with others. When two blocks collide I want to test to see if certain characteristics of each block are equal (e.g. size, color, orientation, etc.). Each block is it's own object, will handle it's own movement and collision detection, and will have accessor methods for size, color, orientation, etc.
Here's my question:
Am I correct in thinking that each block is a separate unit in itself and doesn't know anything about the other blocks? Block A, for instance, collides with Block B and only knows that it collided with something, but doesn't know it was another block? If this is so, then how do I do a proper comparison? How do I tell which block has collided with which block and get access to each block's data and where do I do the comparison? In the layer?
I'd love to be pointed in a decent direction here. I'm not really sure if what I'm wanting to do is even doable? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用通常与 cocos2d 一起提供的物理引擎 - chipmunk 或 box2d。物理引擎将为您处理碰撞,如果您实现碰撞回调,那么您可以知道两个对象何时相互碰撞。然后,您可以检查每个对象的特征并做出相应的反应。 本教程关于 Chipmunk 和 cocos2d 集成可能会有所帮助。
You could use a physics engine that usually comes along with cocos2d- either chipmunk or box2d. The physics engines will take care of collisions for you, and if you implement collision callbacks then you can know when two objects hit each other. You can then check the characteristics of each object and react accordingly. This tutorial on Chipmunk and cocos2d integration might be helpful.