cocos2d android中的CGRect精灵问题

cocos2d android中的CGRect精灵问题,android,cocos2d-iphone,ccsprite,cocos2d-android,Android,Cocos2d Iphone,Ccsprite,Cocos2d Android,在我的cocos2d android游戏项目中,随机数目的目标从顶面落到飞船上,当两个相交的飞船都应该被删除时,我已经完成了编码,但“飞船”没有被删除。是不是CGRect精灵不会被删除?有人知道吗 LinkedList<CCSprite> targetsToDelete = new LinkedList<CCSprite>(); for (CCSprite target : _targets) { CGRect targetRect = CGRect.make(

在我的cocos2d android游戏项目中,随机数目的目标从顶面落到飞船上,当两个相交的飞船都应该被删除时,我已经完成了编码,但“飞船”没有被删除。是不是CGRect精灵不会被删除?有人知道吗

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

    }

}
LinkedList targetsToDelete=new LinkedList();
对于(CCSprite目标:_目标)
{
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”);
船舶设置位置(CGPoint.ccp(30200));
船舶设定点(CGPoint.ccp(0,0));
船舶设置标签(25);
addChild(船舶);
//ship.setVisible(假);
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(“要删除的发货继续…:”+卷);
if(CGRect.相交(targetRect,shipRect))
{
System.out.println(“船舶相交:)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@…:“+卷);
removeChildByTag(25,假);
}
}

您的代码处于更新循环中,这样您每次都在向循环中添加ship。它实际上是在删除,您可能看不到效果。从更新代码中取出添加船舶的代码,并将其放入初始化代码中,使船舶精灵成为全局的,然后检查交叉点。

是否为目标中的每个目标添加全新的
ship
?感谢您的回复,只有一艘船和许多目标@kreiris类似于parent.removeChild(node,true);必须给予什么@克里里说的是行
CCSprite ship=addChild(ship)。对于_targets中的每个目标,您创建一个“ship150.png”精灵并将其添加到层中(我假设您的代码在层的更新循环中被调用)。这是有意的吗?当你写这段代码时,你真的想要这样的行为吗?是的,我的代码在更新循环中,因为在更新方法中使用了目标,所以把这段代码放在这里,对于目标中的每个目标,我不想创建一个“船”精灵,只有一个就足够了@克里里