如何在cocos2d-android游戏中删除单个精灵

时间:2013-06-11 05:42:07

标签: android cocoa-touch cocos2d-iphone cocos2d-android

在这个cocos2d-android游戏中,如果两个精灵(船只和目标)相交的船应该消失,这就是我给出的代码,但是在交叉后无法移除精灵,我搜索了谷歌,但没有任何帮助我出去了,这是cocos2d-iphone中的代码“[_targets removeObject:sprite];”但找不到任何类似的cocos2d-android,如果有人知道这对我有帮助。

if (CGRect.intersects(targetRect, shipRect))
{
    System.out.println("ship deleted: " + ship);                         
    this.removeChild(ship, true);
}

1 个答案:

答案 0 :(得分:0)

您想稍后移除船只,而不是在此IF中,对吗?

因此,您需要将船只添加到数组中,然后循环此数组并使用removeFromParent方法删除所有船只。

iOS cocos2d-iphone代码[_targets removeObject:sprite]是从数组中删除对象的代码;

相关问题