Hi!
I am trying to implement some simple collision detection with CCRect::CCRectIntersectsRect.
My main player object resides on it’s own layer. A layer that does not move. The player stores a separateCCPoint for his position, so that the level class can offset the level-elements layer accordingly and thus emulate a camera rig.
The problem that I am facing is that CCPoint::getPosition* only returns the position relative to the layer the node is on. Hence, testing the collision of objects across layers becomes a chore.
I have successfully solved my problem by reverse-calculating all offsets involved and the code is posted below. However I wonder if there is an easier, more efficient way to solve this. It would be great to simply be able to convert a node’s position to the most top layer position or even screen space automatically. Is that possible?
My solution:
@
// Get the on-screen bounding box
CCRect collectibleRect = CCRectMake~~>getPosition.x + pParallaxNode~~>getPosition.x - ->getContentSize.width / 2 ( it )>getScale ), ->getContentSize.height / 2 ( it )->getScale ),
>getPosition.y + pParallaxNode>getPosition.y
->getContentSize.width ( it )->getScale,
->getContentSize.height ( **it )->getScale
);
@
’**it’ is a pointer to a CCSprite