当使用CCScaleTo或CCScaleBy时,CCSprite被移动 [英] CCSprite is moved when using CCScaleTo or CCScaleBy
问题描述
我几乎读过关于锚点和缩放的一切。
现在的情况是这样:
当我点击屏幕,sprite的宽度将减少约%50和高度将增加大约相同的规模。
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];
我不明白为什么缩放让sprite移动。
如果我在屏幕上的位置(100,100)有一个尺寸为40x60的sprite,当我缩放它,它向左移动。为什么?
感谢。
图像不位于图的质心处。在下一张图片中,您应该将锚点设置为红点,ccp(0.85,0.5)大约!
Image:Anchor Point,Moon,center的质量
如果您的锚点位于中心(0.5,0.5),当前一个图形水平缩放时,它将向左移动这是你的问题吗?
(只在视觉上!)
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.
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?
这篇关于当使用CCScaleTo或CCScaleBy时,CCSprite被移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!