How to get the absolute position of a child sprite (i.e. a child of a parent sprite) in Cocos2d

I have two parent sprites.

Each parent has two child sprites.

Although the two parent sprites have different positions, it seems that the position of the child sprites is the same for both parents.

I mean that although the children are attached to the parent object and visually seem to move, no matter where the parents move, the value of the β€œposition” property point remains unchanged.

When you move your parents around the screen, you can also see how the children move. There the situation is really changing.

But the "position" property for children always remains unchanged.

What am I doing wrong? How to get the absolute position of a child sprite?

+4
source share
1 answer

To get one child absolute position relative to the screen (or, more precisely, the scene), use this:

CGPoint absolutePosition = [childSprite convertToWorldSpace:childSprite.position]; 

I don’t think you were doing something wrong. The position of the child relative to his parent, so it makes sense that the positions of the children do not change.

+4
source

Source: https://habr.com/ru/post/1382539/


All Articles