cocos2d 精灵碰撞检测边界框
我有 2 个精灵。我使用边界框来检查与 CGRectIntersectsRect 的碰撞。但它不起作用。 HBBall 和 HBpaddle 有一个名为 image 的 CCSprite。
初始化:
ball = [[HBBall alloc] init];
ball.position = ccp(150, 50);
[self addChild:ball];
[update addObject:ball];
paddle1 = [[HBPaddle alloc] init];
paddle1.position = ccp(50, 160);
[self addChild:paddle1];
更新:
if (CGRectIntersectsRect([paddle1.image boundingBox], [ball.image boundingBox]))
CCLOG(@"ball hit paddle");
CGRectIntersectsRect 返回始终为 true。有人有想法吗?
I got 2 sprites. I use the boundingbox to check for collision with CGRectIntersectsRect. But it is not working.
HBBall and HBpaddle has a CCSprite called image.
Init:
ball = [[HBBall alloc] init];
ball.position = ccp(150, 50);
[self addChild:ball];
[update addObject:ball];
paddle1 = [[HBPaddle alloc] init];
paddle1.position = ccp(50, 160);
[self addChild:paddle1];
Update:
if (CGRectIntersectsRect([paddle1.image boundingBox], [ball.image boundingBox]))
CCLOG(@"ball hit paddle");
CGRectIntersectsRect retuns always true. Does anyone have an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能直接传递边界框,因为它是相对于精灵的。您必须像这样传递绝对 CGRect 边界框:
进行必要的调整!
希望可以帮忙!
you cant pass directly the bounding box, because it's relative to the sprite. You MUST pass the absolute CGRect boundingbox like this:
make necessary adjustments!
hope can help!
http://www .iphonedevsdk.com/forum/iphone-sdk-game-development/17082-cocos2d-collision-detection- Between-sprites.html?你用谷歌搜索过吗?这似乎是 cocos2d 框架中一个非常基本的问题。
http://www.iphonedevsdk.com/forum/iphone-sdk-game-development/17082-cocos2d-collision-detection-between-sprites.html ? Have you googled? This seems like it would be a pretty basic issue in the cocos2d framework.