Actionscript 3 将精灵的锚点设置为中间
我以如下编程方式生成精灵:Actionscript 3 将精灵的锚点设置为中间,actionscript-3,actionscript,rotation,sprite,Actionscript 3,Actionscript,Rotation,Sprite,我以如下编程方式生成精灵: this.food = new Sprite(); this.food.graphics.beginFill(0xFFFFFF); this.food.graphics.drawRect(0, 0, 10, 10); this.food.filters = [new GlowFilter(0xFF6699, .80, 5, 5, 2, 2, false, false)]; this.food.graphics.endFill(); this.food.x = this
this.food = new Sprite();
this.food.graphics.beginFill(0xFFFFFF);
this.food.graphics.drawRect(0, 0, 10, 10);
this.food.filters = [new GlowFilter(0xFF6699, .80, 5, 5, 2, 2, false, false)];
this.food.graphics.endFill();
this.food.x = this.x;
this.food.y = this.y;
this.stage.addChild(this.food);
稍后我会这样做:
public function update():void
{
// Spin the food
this.food.rotation += 1;
}
我基本上希望食物雪碧围绕它的中心慢慢旋转,而不是它的x和y值,它是雪碧的左上角
如何使锚点成为精灵的中心?使用的前两个参数偏移图形:
drawRect(-5, -5, 10, 10);
参数
x:Number
-一个数字,表示相对于
父显示对象的注册点(以像素为单位)。y:Number
-一个数字,表示相对于
父显示对象的注册点(以像素为单位)。width:Number
-矩形的宽度(以像素为单位)。height:Number
-矩形的高度(以像素为单位)
想法是从
x
和y
到中心减去宽度和高度的一半。使用的前两个参数偏移图形:
drawRect(-5, -5, 10, 10);
参数
x:Number
-一个数字,表示相对于
父显示对象的注册点(以像素为单位)。
y:Number
-一个数字,表示相对于
父显示对象的注册点(以像素为单位)。
width:Number
-矩形的宽度(以像素为单位)。
height:Number
-矩形的高度(以像素为单位)
想法是从x
和y
到中心减去宽度和高度的一半。我找到了另一种使用矩阵对象和变换方法的方法。
也许这还是有帮助的
我发现了另一种使用矩阵对象和变换方法的方法。
也许这还是有帮助的