2012-03-29 51 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的。