2012-07-05 57 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