0

In this cocos2d-android game, if two sprites(ship and target) intersect ship should get disappeared, this is how i had given the code but could not remove the sprite after intersection, i searched through out google, but nothing helped me out, this is the code in cocos2d-iphone " [_targets removeObject:sprite];" but could not find anything similar for cocos2d-android, please if anybody know this help me.

if (CGRect.intersects(targetRect, shipRect))
{
    System.out.println("ship deleted: " + ship);                         
    this.removeChild(ship, true);
}
Kreiri
  • 7,840
  • 5
  • 30
  • 36
samm
  • 482
  • 5
  • 14

1 Answers1

0

You want to remove the ships later, not in this IF, right?

So, you need to add the ship to an array, and later loop this array and remove all ships using removeFromParent method.

The iOS cocos2d-iphone code [_targets removeObject:sprite] is the code to remove an object from array;

Bivis
  • 1,320
  • 1
  • 10
  • 24
  • i wanted to remove the ship in the "IF" statement itself, even added the ship into array and tried it out but could not get, i'm using cocos2d-android code @Mauricio Tollin – samm Jun 12 '13 at 04:38
  • Did you check if your class ("this") is really the parent of ship? Try to use self.removeFromParent and see what happens. – Bivis Jun 12 '13 at 19:10