skytz
skytz

Reputation: 2201

Touch a sprite without boundingBox

So i'm trying to move multiple sprites on the screen at the same time. The problem is that if the 2 sprites are close to each other the position becomes the same (so the bounding box is the same) and i can't seem to pull them apart.

I'm using the "standard" CGRectContainsPoint(sprite1.boundingBox,location).

What i need is to get the sprite on top regardless of boundingBox. Any ideas?

Upvotes: 0

Views: 303

Answers (2)

skytz
skytz

Reputation: 2201

hah..i fixed in the easiest way possible :\

 if (CGRectContainsPoint (sprite1.boundingBox,location)){
 sprite1.position=location;
 }else if (CGRectContainsPoint (sprite2.boundingBox,location)){
 sprite2.position=location;
 }

the way this behaves is that if the bounding boxes are the same..it only takes one..not the 2nd one

Upvotes: 0

MechEthan
MechEthan

Reputation: 5703

One way would be to start assigning explicit z values to sprites you add, using CCNode's -(void) addChild: (CCNode*)node z:(NSInteger)z method.

Then, when you get multiple sprites back from your bounding test, only move the one with largest z value.

Upvotes: 1

Related Questions