2013-06-25 59 views
0

在我的cocos2d-的Android遊戲項目,目標隨機數從頂面落在船上,當兩個相交船舶應被刪除,我也做了編碼,但「船」是不是被刪除。 CGRect精靈是不會被刪除的?有人知道嗎?的CGRect精靈問題在cocos2d-的Android

LinkedList<CCSprite> targetsToDelete = new LinkedList<CCSprite>(); 

for (CCSprite target : _targets) 
{ 
    CGRect targetRect = CGRect.make(target.getPosition().x - (target.getContentSize().width), 
            target.getPosition().y - (target.getContentSize().height), 
            target.getContentSize().width, 
            target.getContentSize().height); 



    CCSprite ship = CCSprite.sprite("ship150.png"); 
    ship.setPosition(CGPoint.ccp(30,200)); 
    ship.setAnchorPoint(CGPoint.ccp(0,0)); 
    ship.setTag(25); 
    addChild(ship); 
    // ship.setVisible(false); 


    CGRect shipRect = CGRect.make(ship.getPosition().x - (ship.getContentSize().width/2), 
            ship.getPosition().y - (ship.getContentSize().height/2), 
            ship.getContentSize().width, 
            ship.getContentSize().height); 
    System.out.println("ships to delete continue... : " + volume); 
    if (CGRect.intersects(targetRect, shipRect)) 
    { 

     System.out.println("ships intersected:)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@... : " + volume); 
     removeChildByTag(25, false); 

    } 

} 
+0

是您爲_targets中的每個目標添加全新的'ship'船舶嗎? – Kreiri

+0

感謝您的回覆,只有一艘船和很多目標@Kreiri –

+0

就像是parent.removeChild(node,true);必須得到? @Kreiri –

回答

0

你的代碼是在更新循環,這種方式要添加的船你的循環每time.Its實際刪除你可能不會看到效果。取出代碼,將你的船從你的更新代碼中加入並放入初始化代碼中,使船舶精靈成爲全局的,然後檢查相交。