2013-06-25 109 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实际删除你可能不会看到效果。取出代码,将你的船从你的更新代码中加入并放入初始化代码中,使船舶精灵成为全局的,然后检查相交。