简体   繁体   English

Haxe Typedef阵列?

[英]Haxe Typedef Array?

I'm very new to Haxe, and trying to make a simple tile-map creation program with OpenFL. 我对Haxe很新,并试图用OpenFL制作一个简单的瓷砖地图创建程序。 However, I'm not sure how to make an array of classes (each individual tile types) I have made. 但是,我不知道如何制作一组类(每个单独的瓷砖类型)。 It seems that a typedef is what I want, but I'm not sure how to incorporate this into an array so I can iterate through them. 似乎typedef是我想要的,但我不知道如何将它合并到一个数组中,所以我可以遍历它们。 Thanks in advance, - RealFighter64 在此先感谢, - RealFighter64

I assume the tile classes are all subclasses of a base class. 我假设tile类是基类的所有子类。 In this case, just put them into an Array<Class<Base>> as follows: 在这种情况下,只需将它们放入Array<Class<Base>> ,如下所示:

class Base {

}

class A extends Base {
    public function new():Void {}
}
class B extends Base {
    public function new():Void {}
}
class C extends Base {
    public function new():Void {}
}

class Test {
    static function main() {
        var classArray:Array<Class<Base>> = [A, B, C];
        for (cls in classArray) {
            var inst = Type.createInstance(cls, []);
        }
    }
}

If they do not have a common super class, use an Array<Dynamic> instead. 如果它们没有公共超类,请改用Array<Dynamic>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM