0
votes

How to change anchorpoint and don't change the position??

I have a sprite which has anchor 0,0.

However, I would like to change anchor 0.5,0.5 temporary,because I would like to rotate the sprite.

What I want to do is like this.

  CGPoint anchorPointOriginal = ccp(0,0);
  CGPoint anchorPointTemp = ccp(0.5,0.5);


  [mySprite setAnchorPoint:anchorPointTemp];

  //Rotate

  [mySprite setAnchorPoint:anchorPointOriginal];

But when I change the anchorPoint, sprite also moves the position according to the new anchorpoint

Is it possible to keep the sprite position and only change the anchor point??

2
Why do you need to the anchor point to be (0,0)?0x141E
I need to use 0,0 anchor for first spawning. it appears scaling up from the left bottomwhitebear

2 Answers

1
votes

Try changing the sprite's location when you change the anchor point. Something like...

mySprite.anchorPoint = anchorPointTemp;

mySprite.position = CGPointMake(mySprite.position.x+mySprite.size.width/2,
             mySprite.position.y+mySprite.size.height/2);

This will change the anchorPoint and move the sprite to correctly compensate for the position change (due to the anchor point change).

You will need to undo this if you want to change the anchor point back to CGPointZero.

0
votes

if you are using cocos2d-iphone 2.0 or later version then you could simply use the
ignoreAnchorPointForPosition property

mySprite.ignoreAnchorPointForPosition = YES;