2012-07-05 58 views
1

嗨stackoverflow社区!cocos2d与父Sprite的儿童精灵碰撞检测

如何检测cocos2d中的父Sprite与子Sprite的碰撞?

目前,我有我的代码是这样的:

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

现在我怎样检测 “跳线” & “高原” 之间的冲突?

感谢您的帮助!

+0

首先,为什么你初始化你的开发平台两次?你会在这里得到内存泄漏。第二个你可以将比较精灵的矩形坐标转换为世界坐标,然后比较它们 – Morion

回答

-1

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

if(CGRectIntersectsRect([jumper boundingBox], [plat boundingBox])) { 
    //Handle collision<br> 
} 
+0

这不起作用.. – mm24