Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何覆盖cocos2d android中的CCTouchStart(移除重叠精灵)_Android_Cocos2d Iphone_Cocos2d Android - Fatal编程技术网

如何覆盖cocos2d android中的CCTouchStart(移除重叠精灵)

如何覆盖cocos2d android中的CCTouchStart(移除重叠精灵),android,cocos2d-iphone,cocos2d-android,Android,Cocos2d Iphone,Cocos2d Android,我有一组精灵列表。如果精灵重叠,我想移除最上面的精灵 if(popRect1.containsPoint(popRect1,位置)) { BaloonList1.remove( baloons ); baloons.removeSelf(); } BaloonList2.remove( baloons );

我有一组精灵列表。如果精灵重叠,我想移除最上面的精灵

if(popRect1.containsPoint(popRect1,位置)) {

                       BaloonList1.remove( baloons );
                       baloons.removeSelf();

                 }
                       BaloonList2.remove( baloons );
                       baloons.removeSelf();

                 }             
if(popRect2.containsPoint(popRect2,位置)) {

                       BaloonList1.remove( baloons );
                       baloons.removeSelf();

                 }
                       BaloonList2.remove( baloons );
                       baloons.removeSelf();

                 }             
当同一列表中的两个精灵重叠时,如果我触摸它们,只有最顶端的精灵会被移除…如果两个精灵来自不同的列表,当我触摸最顶端的精灵时,它们都会被移除(就像我的触摸被截取一样..我认为这是因为两个触摸点都是精灵的有界矩形)…我搜索了很多。有人说override TouchBegind..registerWithTouchDispatcher…有人知道吗?????我知道这可能是一个简单的问题4u伙计们。请告诉我你是否想要更多关于此的代码或描述

addChild(CCNode child,int z)

如果将z的值设置为0,1,2,3,4..,依此类推

在此之后,当您触摸屏幕时,z的值决定移除精灵。
在发生重叠的情况下,要首先删除的精灵,请将z的值指定给其他精灵的最大值。

您还必须保存首先添加精灵的状态。 假设我们有两个精灵A和B

情况1)如果A和B具有相同的z值

如果我们添加B精灵,然后再添加一个精灵,那么A将出现在B精灵的上方。因此,我们需要设置最后添加哪个精灵的状态。根据这一点,您必须删除该精灵。 情况2)如果A和B具有不同的z值 在这种情况下,您有清晰的图片。具有更多z值的精灵将显示在其他精灵的上方。因此您可以删除该精灵


在您的情况下,如果您使用案例1,那么您还必须保持th状态

假设我们有两个ArrayList:ArrayList 1和ArrayList 2

我们将状态保存为ArrayList:ArrayListStatus1,ArrayListStatus2

我们已将状态初始化为1。 int状态=1

如果我们在任何ArrayList中添加精灵,我们还必须将in-ArrayList状态添加到相应的状态数组列表中,并增加状态,以便下次添加精灵时,它将添加一个加一个状态

现在我们有了订单,这样我们可以应用检查哪个精灵在上面。状态对应于那里的状态arraylist