Skip to content Skip to sidebar Skip to footer

How Can I Override Cctouchbegan In Cocos2d-android( Removal Of Overlaying Sprites)

I have a set of sprite lists.i want to remove the topmost lying sprite if the sprites overlap. if ( popRect1.containsPoint( popRect1, location ) ) {

Solution 1:

addChild(CCNode child, int z);

if you set the value of z like 0,1,2,3,4.. and so on ..

after this when you touch on the screen the value of z is decided to remove the sprite. what sprite you want to remove first in the case overlap is occur, give the value of z is max. to the others.

Solution 2:

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

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

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.


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

Assuming we have two ArrayList: ArrayList1 and ArrayList2

and we are saving status as ArrayList: ArrayListStatus1,ArrayListStatus2

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

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.

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

Post a Comment for "How Can I Override Cctouchbegan In Cocos2d-android( Removal Of Overlaying Sprites)"