I have a CCSprite which is a child of another node. The sprite is a full-screen effect so it should always be drawn at the same position ignoring the position of the parent.(For example always at position 0/0)
I can't move the sprite to another layer because the rendering order is correct at the moment. Does anyone know a clean solution for my problem ? I want that the sprite has always the same absolute coordinates and ignores the position of the parent.
Sprite position independent from parent - clean solution ?
(7 posts) (4 voices)-
Posted 5 months ago #
-
Try setting the x and y position of the sprite to the negative of the x and y position of the layer. So basically in the update method of the layer you would have something like:
sprite.position = ccp(-1*self.position.x, -1*self.position.y);
This way if the layer is at -50x, the sprite will be at 50x inside the layer to compensate.
I haven't tested the this yet though. Hope it works. Good luck.Posted 5 months ago # -
Thx for the fast answer, sounds like a good solution for my problem.
Posted 5 months ago # -
Or you can use sprite.position = [self convertToNodeSpace:newPosition];
Besides you can rewrite setter for this object:- (void) setPosition:(CGPoint) newPosition
{
super.position = [self.parent convertToNodeSpace:newPosition];
}Posted 5 months ago # -
Afair there is no need to hack around with positions, there is a honorParentTransform property of CCSprite.
Posted 5 months ago # -
Ahh, totally forgot about that one. Nice!
Posted 5 months ago # -
Thank you, that's a nice solution!
Posted 5 months ago #
Reply
You must log in to post.