如何在cocos2d-x(c ++)ios游戏中检测CCArray中精灵的碰撞 [英] How to detect collision of sprites which are in a CCArray in cocos2d-x (c++) ios game

查看:118
本文介绍了如何在cocos2d-x(c ++)ios游戏中检测CCArray中精灵的碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cocos2dx ios游戏开发的初学者。我在CCArray中有12个精灵,他们随机地从屏幕的顶部到底部掉落。任何精灵都可以随时出现。我已经完成了分层,即数组索引0处的精灵将在第12层出现,而索引1将在第11层出现,依此类推。因此首先出现的精灵出现在第二个精灵之前。但重点是这种情况并非总是如此。精灵可以先来到索引5然后再索引4,依此类推。那么如何检测同一阵列中存在的精灵的碰撞,这样如果它们碰到彼此的边界框,那么我可以让它们慢一秒或其他什么,这样它们就不会相互重叠。我没有使用Box2d并且不想使用它。我只想在不使用box2d的情况下回答,只在cocos2dx中使用c ++。任何可以帮助我的人谢谢

I am a beginner in cocos2dx ios game development.I have 12 sprites in a CCArray and they are falling from top to bottom of the screen randomly. Any sprite can appear any time. I have done layering that the sprite at array index 0 will come at layer 12 and at index 1 will come at layer 11 and so on.So that the sprite coming first appear ahead of the sprite coming second. But the point is this situation is not always true.The sprites can come like index 5 first and then index 4 and so on. So how to detect collision of the sprites present in the same array such that if they touch each others bounding box then I can make them slow for a second or something else so that they don't overlap with each other.I am not using Box2d and don't want to use it. I just want answer without using box2d and only in cocos2dx using c++.Anyone who can help me Thanks

推荐答案

你需要做的就是在每个精灵周围定义一个矩形然后检查它们是否相交。查看CCRect类,并使用此示例查看此处
All you need to do is to define a rectangle around each sprite and then check if any of them intersect. look into CCRect class and for an example using this see here.


这篇关于如何在cocos2d-x(c ++)ios游戏中检测CCArray中精灵的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆