0
votes

I have a number on CCSprites on screen which have CCNodes placed upon them, and added as children. How can I remove the CCNode child based on touch location (or touched sprite location)?

I have attempted creating a custom method (see below) but am unsure how to fill it in.

 -(void)removeChild:(CCNode*)node location:(CGPoint)location cleanup:(BOOL)cleanup;

Is it possible to specify location with the built in method?

[self removeChild:(CCNode *)[node at location] cleanup:(BOOL)cleanup]
1

1 Answers

0
votes

You can get local rect of your sprite by sending boundingBox message. Then just test your touch position with CGRectContainsPoint function. The only thing you should remember, that you need convert your coordinates(for example, if your sprites are children of some node, then their rects will be relative to it's (0.f, 0.f) coordinate, not to the scene (0.f, 0.f)). Also you should convert your touch location with sending convertToGL: message to CCDirector shared instance.