2012-03-29 54 views
1

我生成精灵编程方式是这样的:设置锚点中间

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值,它是精灵的左上角。

如何让锚点成为精灵的中心?

回答

1

使用drawRect()前两个参数,以抵消所述图形:

drawRect(-5, -5, 10, 10); 

参数

x:Number - 一个数字,指示相对于父显示的 注册点的水平位置对象(以像素为单位)。
y:Number - 一个数字,指示相对于父显示对象的注册点(以像素为单位)的垂直位置。

width:Number - 矩形的宽度(以像素为单位)。
height:Number - 矩形的高度(以像素为单位)。

的想法是从xy到中心减去一半widthheight的。