2013-06-27 47 views
0

主題在Cocos2d-android遊戲中: 要刪除與其他精靈發生衝突後的精靈,我已經使用了spriteRect函數,但是這並沒有讓精靈在相交後被刪除,經過大量的谷歌搜索才知道,它應該從父被刪除, 這裏的代碼如何從父項中刪除精靈cocos2d-android

CGRect ship1Rect = CGRect.make(ship1.getPosition().x - (ship1.getContentSize().width/2), 
           ship1.getPosition().y - (ship1.getContentSize().height/2), 
           ship1.getContentSize().width, 
           ship1.getContentSize().height); 
if (CGRect.intersects(targetRect, ship1Rect)) 
{   
    parent.removeChildByTag(17, true); 
} 

但在這裏,在這條線得到錯誤爲parent.removeChildByTag(17, true);「家長不能得到解決」的錯誤,我要去哪裏錯了,請能任何人都可以告訴

回答

0
ship1.getParent().removeChild(ship1,true); 

ship1.getParent(). removeChildByTag(17,true); 
+0

感謝你的回覆:)仍然沒有被刪除@Sohaib –

0

只能使用 removeChild之(SHIP1,真); insteasd parent.removeChildByTag(17,true);