问题
Hi stackoverflow community!
How do you detect a children sprite collision with a parent sprite in cocos2d?
Currently I have my codes like this:
CGSize screenSize = [[CCDirector sharedDirector]winSize];
parentJumper = [CCSprite spriteWithFile:@"inviBtn.png"];
jumper = [CCSprite spriteWithFile:@"jumperRight.png"];
plat = [[Platform alloc]init];
plat = [Platform spriteWithFile:@"platformBlack.png"];
plat.position = ccp(160,100);
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0/60)];
jumper.anchorPoint = ccp(0.5, 0);
jumper.position = ccp(0, 20);
parentJumper.position = ccp(screenSize.width/2, 0);
[self addChild:plat];
[self addChild:parentJumper];
[parentJumper addChild:jumper];
Now how do I detect the collision between "jumper" & "plat"?
Thanks for your help!
回答1:
Usually you can check collision like this:
if(CGRectIntersectsRect([jumper boundingBox], [plat boundingBox])) {
//Handle collision<br>
}
来源:https://stackoverflow.com/questions/11340024/cocos2d-children-sprite-collision-detection-with-parent-sprite