我以编程方式生成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.x;
this.food.y = this.y;
this.stage.addChild(this.food);
后来我正在这样做:
public function update():void
{
// Spin the food
this.food.rotation += 1;
}
我基本上希望食物精灵围绕它的中心缓慢旋转,而不是它的精灵左上角的x和y值。
如何将锚点作为精灵的中心?
答案 0 :(得分:1)
使用drawRect()
的前两个参数来偏移图形:
drawRect(-5, -5, 10, 10);
参数
x:Number
- 一个数字,表示相对于的水平位置 父显示对象的注册点(以像素为单位)y:Number
- 一个数字,表示相对于的垂直位置 父显示对象的注册点(以像素为单位)。
width:Number
- 矩形的宽度(以像素为单位)height:Number
- 矩形的高度(以像素为单位)。
我们的想法是将width
和height
的一半从x
和y
减去中心。
答案 1 :(得分:0)
我找到了另一种使用Matrix Object和transform方法的方法。 也许它仍然有用。