我如何可以覆盖ccTouchbegan在cocos2d-的Andr​​oid(去除覆盖的精灵) [英] How can i override ccTouchbegan in cocos2d-android( removal of overlaying sprites)

查看:337
本文介绍了我如何可以覆盖ccTouchbegan在cocos2d-的Andr​​oid(去除覆盖的精灵)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组精灵lists.i的希望,如果精灵重叠去除最上面躺着精灵。

I have a set of sprite lists.i want to remove the topmost lying sprite if the sprites overlap.

如果(PO prect1.containsPoint(PO preCT1,位置))
                   {

if ( popRect1.containsPoint( popRect1, location ) ) {

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

                 }

如果(PO prect2.containsPoint(PO preCT2,位置))
                   {

if ( popRect2.containsPoint( popRect2, location ) ) {

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

                 }             

在同一名单重叠两个精灵,如果我触摸它们只有最上面的精灵将被删除......如果2精灵来自不同的列表,当我触摸两者删除的最顶端的精灵(就像我的触摸拦截..我认为它的发生,因为这两个触摸点与精灵的矩形有限)。我找遍alot.Some说覆盖TouchBegan..registerWithTouchDispatcher ......没有任何一个有任何想法???????我知道这可能是一个简单的问题4U guys.Please让我知道如果u想要更多的code或说明有关本

When two sprites of same list overlap and if i touch them only the topmost sprite will be removed...if 2 sprites are from different list and when i touch the topmost sprite both of them are removing(Like my touch is intercepting..I think its happening because both the touch points are with the bounded rectangles of the sprites)..I searched alot.Some say override TouchBegan..registerWithTouchDispatcher...DOes any one have any idea ??????? i know this could be a easy question 4u guys.Please let me know if u want more code or description regarding this

推荐答案

您也必须保存这些精灵首先加入居留制。
假设我们有2个精灵A和B

You have to also to save the staus of which sprite is added firstly. Assuming we have 2 sprites A and B.

案例1)如果A和B都具有相同的z值

Case 1) if both A and B having same z values

和如果我们将B加入精灵是一个精灵则A将出现对B以上精灵之后。因此,我们需要设置的精灵是最后加入的状态。据你必须删除精灵。
案例2)如果A和B具有不同z值
在这种情况下。你有清晰的画面。它有更多的Z值的精灵就会出现上述以外。所以,你可以删除精灵。

If we add B sprite and after that A sprite then A will appear above the B sprite. So we need to set status of which sprite is added lastly. According to that you have to remove the sprite. Case 2) If A and B having different z values In this case. You have clear picture. The sprite which have more z value will appear above other. So you can remove that sprite.

在你的情况,如果你使用的情况下1,那么你必须还要保持状态的第

In your case if you using case 1 then you have also to maintain th status.

假设我们有两个的ArrayList:ArrayList1和ArrayList2

Assuming we have two ArrayList: ArrayList1 and ArrayList2

和我们节约地位的ArrayList:ArrayListStatus1,ArrayListStatus2

and we are saving status as ArrayList: ArrayListStatus1,ArrayListStatus2

我们的状态都初始化为1。
INT状态= 1;

We have initialize the status to 1. int status=1;

如果我们在我们还为在ArrayListStatus添加到相应的状态数组列表,并有精灵的时候,我们将增加它会增加一加状态,以便下一次递增状态的任何ArrayList的添加一个精灵。

If we add a sprite in any ArrayList we have also to add the in ArrayListStatus to corresponding status array list and have increment the status so next time when sprite will we added it will add one plus status.

现在我们有秩序,所以我们可以将支票精灵以上。状态对应有状态的ArrayList

Now we have the order so we can apply the check which sprite is above. The status is corresponding to there status arraylist.

这篇关于我如何可以覆盖ccTouchbegan在cocos2d-的Andr​​oid(去除覆盖的精灵)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆