Hi guys,
A while back, I made a 2D point-and-click game with Unreal Engine. [You can find some more info here :
AndHalfAFish Games, and there's also a download link at the bottom of the "RIP" post in case you want to try it out.]
I would like to port it to HaxeFlixel.
I
was thinking of using FlxGroups for each of the 'views' you typically
have in a point-and-click game, and then use kill() and revive() to
switch views in the game.
Question 1 : would you consider this to
be an ok approach, or is there some other preferred way of doing this
in HaxeFlixel ?
Question 2 : when I tried it out with 2 test view classes like this :
class View_Test1 extends FlxGroup
{
var counter:Int = 0;
var txt:FlxText;
public function new()
{
super();
txt = new FlxText(50, 50, -1, Std.string(counter));
add(txt);
add(new FlxButton(100, 50, "increase counter", increaseCounter));
add(new FlxButton(100, 100, "goto pink", gotoTest2));
}
private function increaseCounter() : Void
{
trace("click");
txt.text = Std.string(++counter);
}
private function gotoTest2):Void
{
GameState.game.switchToView("View_Test2", View_Test2);
}
}
And in GameState :
class GameState extends FlxState
{
var views:Map<String, FlxGroup> = new Map(); //coll of all Views
public var currentView:FlxGroup= null;
...
public function switchToView(newView:String, newClass:Class<FlxGroup>):Void
{
//create an instance if none exists
if ( !views.exists(newView)) {
views[newView] = Type.createInstance(newClass, new Array());
add(views[newView]);
}
//switch the current view with a new one
if(currentView != null) {
currentView.kill();
}
currentView = views.get(newView);
currentView.revive();
currentView.forEach(function(member) member.revive());
}
}
Then I find that the first time I switch views, the value of the counter in View_Test1
is not persisted (reset to 0). In all subsequent switches between the
FlxGroups, the values for the counters are persisted ...
So ... What am I doing wrong here ? Or did I misunderstand the use of kill() and revive() ?
Thank you for your thoughts on this !