我正在使用FlashDevelop測試我想用於遊戲的菜單類型系統,並且我遇到了嚴重問題,無論是寬度還是高度,還是Sprite子類的ScaleX和ScaleY(我不確定哪個集合導致問題)。我讀過很多似乎解決了我的問題的東西,包括在添加任何子項後調整子類的大小,但沒有一個能夠工作。現在,我有3個獨立的類。AS3:ScaleX/ScaleY和寬度/高度問題
主營:
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var BF:BFi = new BFi;
this.addChild(BF);
this.width = 640;
this.height = 480;
trace(this + "Dimensions: " + width + ", " + height);
trace(this + "Coordinates: " + x + ", " + y);
}
}
BFI:
public class BFi extends Sprite
{
public function BFi()
{
var BFMenu:BFiMenu = new BFiMenu;
addChild(BFMenu);
trace(getChildAt(0));
this.x = this.y = 0;
this.width = 640;
this.height = 480;
BFMenu.x = this.y = 0;
BFMenu.width = 640;
BFMenu.height = 480;
trace(this + "Dimensions: " + width + ", " + height);
trace(this + "Coordinates: " + x + ", " + y);
}
}
和BFiMenu:
public class BFiMenu extends Sprite
{
[Embed(source = "../Assets/Button1.png")]private var Button1:Class;
public function BFiMenu()
{
var Bounds:Sprite = new Sprite;
Bounds.graphics.lineStyle(2, 0, 1);
Bounds.graphics.drawRect(0, 0, 640, 480);
addChild(Bounds);
var NewButton:ComplexButton = new ComplexButton(220, 405, 200, 50, Button1, "PLAY", "Block", 50, 0x000000, function Button1(e:MouseEvent):void { /*parent.removeChildAt(0);*/ });
//var NewButton:ComplexButton = new ComplexButton(0, 0, 200, 50, Button1, "PLAY", "Block", 50, 0x000000, function Button1(e:MouseEvent):void { parent.removeChildAt(0); });
addChild(NewButton);
this.width = 640;
this.height = 480;
trace(this + "Dimensions: " + width + ", " + height);
trace(this + "Coordinates: " + x + ", " + y);
trace(NewButton + "Dimensions: " + NewButton.width + ", " +NewButton.height);
trace(NewButton + "Coordinates: " + NewButton.x + ", " + NewButton.y);
}
}
命名爲 「邊界」 的矩形有我想要的高度和寬度(640×480) ,但我放置的按鈕應該具有大約450的y座標,而是具有接近800的y值,並且顯然是dis但仍然在屏幕上,儘管高度僅爲480.
被調用的「ComplexButton」類是我自己的按鈕類,並且我已經測試了足夠多的信息,知道它可以正常工作。當我運行這個程序時,它扭曲了一切,沒有什麼是我想要的。任何幫助將非常感激。
你能提供它看起來的樣子和它應該看起來的樣子的照片嗎?以及您正在縮放的代碼 – 2013-04-10 11:04:44