Reputation: 12433
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??
Upvotes: 0
Views: 205
Reputation: 39
if you are using cocos2d-iphone 2.0 or later version then you could simply use the
ignoreAnchorPointForPosition property
mySprite.ignoreAnchorPointForPosition = YES;
Upvotes: 0
Reputation: 12753
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.
Upvotes: 1