Hey all,
Not sure this is even possible in Haxe, but here's what I'm trying to do:
class A { }
class B { }
class C { }
class Main {
private var classes:Array<Dynamic>;
private var index:Int;
function new(){
index = 0;
classes = [A, B, C];
}
function nextInstance():Dynamic{
klass = classes[index];
return new klass();
}
}
main=new Main();
main.nextInstance(); # Returns in instance of A
main.nextInstance(); # Returns an instance of B
main.nextInstance(); # Returns an instance of C
Hopefully this example makes sense.
I'm creating a game and each level is a sub-class on my class Level. In the game, I want to have a list of the Level classes and just instantiate the next one once a level is complete. I could just create instances of every level on initial app load, but that seems wasteful and unnecessary.
Thanks!