如何找到CCSprits之间的碰撞检测?
我试图找到两个精灵之间的碰撞检测(下图中用黑色圈出)
这是我试图通过比较两个精灵的x坐标来帮助找到的代码,但不成功
看看并告诉我什么是错误
- (void)update:(ccTime)dt {
NSLog(@"Target y %f, player y %f",target.position.y, player.position.y);
if(target.position.y==player.position.y)
// if((target.position.x==player.position.x)&&(target.position.y==player.position.y))
// if((sprite.position.y==player.position.y)||(sprite.position.y==player.position.y))
{
Nslog (@"Matched");
//do Something
}
}
I am trying to find collision detection between Two Sprits ( encircle with black color in below picture)
here is the code from which i m trying to find with the help by compairing x cordinate of both sprits but unsuccessful
have a look and tell me what is the mistake
- (void)update:(ccTime)dt {
NSLog(@"Target y %f, player y %f",target.position.y, player.position.y);
if(target.position.y==player.position.y)
// if((target.position.x==player.position.x)&&(target.position.y==player.position.y))
// if((sprite.position.y==player.position.y)||(sprite.position.y==player.position.y))
{
Nslog (@"Matched");
//do Something
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CCNode 类是CCSprite 类的父类,它有一个CGRect 类型的boundingBox 属性。使用玩家和目标对象的此属性,您可以使用以下命令检查碰撞...
The CCNode class which is the parent of the CCSprite class has a boundingBox property of type CGRect. Using this property of the player and target objects you can check for collisions using...
你可以看看 CGRectIntersectsRect 如下所示
http://www.icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/
you could have a look at CGRectIntersectsRect like shown here
http://www.icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/