0
votes

I almost have read everything about Anchor Point and scaling. I still have no idea what is going on with a sprites position when i scale it.

The scenario is this:

When i tap on screen, sprite's width will decrease about %50 and height will increase about same scale. Then it will get back to its normal scale.

id scaleUpAction =  [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:.35 scaleX:0.5 scaleY:1.5] rate:1.0];
id scaleDownAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:.35 scaleX:1.0 scaleY:1.0] rate:1.0];
CCSequence *scaleSeq = [CCSequence actions:scaleUpAction, scaleDownAction, nil];
[self.boxShape runAction:scaleSeq];

I dont understand why scaling makes the sprites "move".

If I have a sprite with size 40x60 at position (100, 100) on the screen, when I scale it down , it moves left. Why?

Thanks.

2
scaleX:0.5 scaleY:1.5: that's not 50% in each direction. That's 50% less in X direction, but only 33% up in Y. You probably want scaleY:2.0Stephane Delcroix

2 Answers

0
votes

Generally, when scaling space there is always exactly one point that remains on it's place, other points move. For CCNode this point is the anchor point. So select the point on your node you want to stay in place and make it anchor point

0
votes

Maybe the anchor point of the image is not located at the mass center of the figure. In the next picture you should set the anchor point in red dot, ccp (0.85, 0.5) approx.!

Image: Anchor Point, Moon, center of mass

If your anchor point is located in the center (0.5, 0.5), when the previous figure is scaled horizontally then it will move to the left (Only visually!).

Is this your problem?