2
我正在嘗試使用按鈕編輯主菜單。我有一個名爲MenuAchievementsButton的類,在它的構造函數中,它從文檔類傳遞到舞臺寬度和舞臺高度。當我跟蹤這個時,它是正確的寬度/高度。as3 MovieClip不能正確縮放
我試圖讓按鈕的高度爲舞臺高度/ 100.我試過做這個.height =舞臺高度/ 100,但是每當我這樣做,它給我4倍的結果我想要的,即使當我輸入像5這樣的數字並在Photoshop中測量像素。
此外,當我嘗試移動該對象時,存在類似的問題:當我希望它是20px的正確和下來,結果是80px左右。
任何幫助表示讚賞!
package menus {
import flash.display.MovieClip;
public class MenuAchievementsButton extends MovieClip {
private var _stageWidth, _stageHeight:int;
public function MenuAchievementsButton(stageWidth:int, stageHeight:int) {
_stageWidth = stageWidth;
_stageHeight = stageHeight;
alpha = 1;
rescaleMe();
repositionMe();
trace(_stageWidth, _stageHeight);
}
private function rescaleMe():void {
var oldWidth = this.width;
var oldHeight = this.height;
this.height = _stageHeight/100;
this.width = (this.height * oldWidth)/oldHeight;
}
private function repositionMe():void {
this.x = 20;
this.y = 20;
trace(x,y,width,height);
trace("Stage height is: ",_stageHeight,"Stage height divided by 100 is: ", _stageHeight/100, "And the object's height, which should be stageheight/100 is:", this.height);
//Gives Stage height is: 800 Stage height divided by 100 is: 8 And the object's height, which should be stageheight/100 is: 8
//Actually, though, it's 36px!
}
}
}
當我嘗試做的scaleX = 1,它使更大!我檢查過,物體不在舞臺上或另一個物體上...任何想法? – DefinitelyNotAPlesiosaur
我找到了解決方案 - 我從主菜單背景創建了按鈕,這些按鈕已被縮放。謝謝您的幫助! :D – DefinitelyNotAPlesiosaur
@ user2696186是的,縮放比例總是相對於父代,而不是全局。 – Vesper