Set Anchor Point Change Postion To Rotated Layer


I have a character which moving on the scene and there is a layer on scene like screenshot at below. I want to change anchor of the layer with character’s position and rotate the layer according to new anchor point. At first interaction I can change anchor point and rotate layer but at second action I set layer anchor point to 0,0 for calculate new point but layer position change if I set anchor point to 0,0. Why layer position change when its rotating?

Initial Position. Layer (0,0) and size (500,500). Character position is (500,500)

Move the character and set new anchor point(Everything is fine)

RotateBy -20 degree(everything is fine)

Move Character to new position

Set anchor point to (0,0) and layer position reset to (0,0). The problem is this.

And after RotateBy -20 degree change position again.

Not sure if this helps your situation or not, but in the past we’ve had situations where we wanted ‘different anchor points’ for the position and rotation. In that case, we set the Cocos2d ‘official’ anchor point for the rotation, and just ‘manually’ altered the position vector ourselves to account for that anchor point (for example, add the half-width to it to move the ‘X-anchor point’ to the middle of the sprite for positioning… keep in mind you’d also need to ‘subtract out’ the rotation anchor point if it isn’t the same, which it sounds like what you want. )
If you are talking about switching rotation anchor points midway through code (like, for example, to rotate on one side of a rectangle for awhile, then on the other side of the rectangle the next time), then I don’t have experience with that, although I would think it would work somehow. (But that’s not much help I know). If that DID in fact work, at the same time you switched the ‘rotation’ anchor point, you would need to subtract it out of your ‘position’ anchor point.