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