Question

I've been looking at many different topics about cocos2d-iPhone's collision detection using the bounding boxes of sprites and I have a sprite that's rotating around a CCNode by an offset position (the sprite is the child of a node so the position is relative to the parent node in CGPoint), and the other sprite isn't connected to a node at all. When I try to do collision detection on the two sprite's bounding boxes it doesn't work because one sprite was added to the node. So, my solution was to copy the sprite using the noded sprites position to make another sprite that isn't connected, but takes the other sprite's coordinates. I figured out how to get the position of the child sprite with the convertToWorldSpace method, but the position is relative to the node, so I get really weird coordinates.

So my question is, is there a way to get collisions to work on the bounding boxes of two different sprites, even though one is the child of another node? If there isn't an easy way to do this, then is there a way to get the absolute position of a sprite in the scene, with points that aren't relative to it's parent? I can add sample code later if needed. I can't right now because I'm using my phone.

Was it helpful?

Solution

Try to use convertToWorldSpace from each parent nodes.

On sprite that is connected to a node, use: [nodeParent convertToWorldSpace:connectedNode]

On sprite that isn`t connected to a node, use: [self convertToWorldSpace:unconnectedNode]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top