CCSprite is moved when using CCScaleTo or CCScaleBy

て烟熏妆下的殇ゞ 提交于 2019-12-13 04:26:38

问题


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.


回答1:


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




回答2:


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?



来源:https://stackoverflow.com/questions/15410367/ccsprite-is-moved-when-using-ccscaleto-or-ccscaleby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!