我正在对 Sprite 进行简单的旋转,但有一个奇怪的行为,即 Sprite 不围绕其左上角旋转。我想我是沿着测试类的左上角旋转,而不是沿着子 Sprite 旋转。我想围绕它的左上角旋转矩形(有点像时钟指针)。代码很短,所以我让代码+图片来解释我的问题:
package
{
import flash.display.Sprite;
public class test extends Sprite
{
public function test()
{
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x000000);
mySprite.graphics.drawRect(100,100,6,120);
mySprite.graphics.endFill();
this.addChild(mySprite);
mySprite.rotation = 45;
}
}
}
看起来太简单了,不可能搞砸,这是结果。红线位于 home 键上方以供引用。第一张图片我设置了 mySprite.rotation=0
,第二张图片是上面显示的代码:
我读过很多关于围绕固定点旋转的内容,我尝试过使用影片剪辑而不是 Sprite 来实现,我什至复制粘贴了 tutorial on rotation没有任何效果。为什么会发生这种行为以及如何解决它?
编辑:谢谢大家,您的所有建议都以不同的方式帮助了我,而且它们都是正确的,所以+1,我将选择我在代码中选择使用的解决方案。
最佳答案
如果您想从中心旋转它,请尝试以下操作:
var mySprite:Sprite = new Sprite();
mySprite.x = mySprite.y = 100;
mySprite.graphics.beginFill(0x000000);
mySprite.graphics.drawRect(-3,-60,6,120);
mySprite.graphics.endFill();
this.addChild(mySprite);
mySprite.rotation = 45;
关于flash - 旋转 Sprite 将 Sprite 从其原始位置移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6599518/