2011-05-18 29 views
1

我有下面的代碼創建一個Sprite在它的矩形:繪製使用圖形類長方形,但移動註冊點

container = new Sprite(); 
container.graphics.beginFill(0x00CCFF, .5); 
container.graphics.lineStyle(1, 0x00CCFF); 
container.graphics.drawRect(rect.x, rect.y, rect.width, rect.height); 
container.graphics.endFill() 
addChild(container); 

唯一的一點是,我想註冊點在中間(而不是左上角)。有沒有辦法在矩形中間設置註冊點,但矩形的位置仍然是正確的?

移到使矩形的左上角是在的,我想矩形是「中間」 ......

+1

這看起來像http://stackoverflow.com/questions/650567/as3-setting-registration-point-of-a-displayobject-with-actionscript的副本 – 2011-05-18 16:23:57

回答

4

你能做的最接近的是:

container.graphics.drawRect(rect.x-rect.width/2, rect.y-rect.height/2, rect.width, rect.height); 

但我認爲這就是你說你不想做的事情。雖然,可能有一種方法可以用Matrix來完成。

編輯:

它看起來像這樣other StackOverflow post會爲你使用變換矩陣對於一些更多的答案,以及一些其他的可能性。