1

嗨 stackoverflow 社区!

你如何检测 cocos2d 中子精灵与父精灵的碰撞?

目前我有这样的代码:

    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];

现在如何检测“跳线”和“平台”之间的碰撞?

谢谢你的帮助!

4

1 回答 1

-1

通常你可以像这样检查碰撞:

if(CGRectIntersectsRect([jumper boundingBox], [plat boundingBox])) {
  //Handle collision<br>
}
于 2012-08-21T15:57:44.063 回答