我正在構建一個基本的遊戲來學習HaxeFlixel的來龍去脈,並且想從MenuState
的PlayState
中調用具有getter/setter屬性的變量。代碼看起來是這樣的:HaxeFlixel:如何在另一個類中調用getter/setter變量
class MenuState extends FlxState
{
@:isVar public var myVar(get, null):Bool;
public function get_myVar():Bool
{
return myVar;
}
}
class PlayState extends FlxState
{
private var _foo:Bool;
override public function create():Void
{
// var ms = new MenuState; doing it like this doesn't return anything
_foo = MenuState.get_myVar();
if (_foo)
{
// do this thing
}
else
{
// do that thing
}
}
}
有了它返回做的事情毫秒變量,沒有它,我得到一個錯誤Class<MenuState> has no field get_myVar
。我相信這可能不是如何編寫代碼,但在這一點上,我只是試圖讓它工作。基本上我想要做的是讓MenuState寫入PlayState
讀取但不能寫入的變量。我會怎麼做呢?