Point-and-click game : FlxGroup kill() and revive() ?

60 views
Skip to first unread message

s c

unread,
Apr 15, 2016, 2:25:52 PM4/15/16
to HaxeFlixel
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 !


s c

unread,
Apr 18, 2016, 3:57:24 AM4/18/16
to HaxeFlixel
Hi guys,

Is there really no one around that can give me some help with this ? 
This is really preventing me from going forward ... :-(

Thanks again !

Sam Bellman

unread,
Apr 19, 2016, 5:14:48 AM4/19/16
to HaxeFlixel
Hi,
This seems a fairly reasonable way of doing things and I can't see why it would reset any other variables on the group, unless you're accidentally changing the state. Could there be some issue with your static variables?
This forum is fairly low traffic so quite often questions slip through if there's not enough info to answer them.

s c

unread,
Apr 19, 2016, 6:06:50 AM4/19/16
to HaxeFlixel
Hi Sam,

Is there a better place to ask questions then this forum ?

Anyway, thanks for your reply ! 
Since this project was for testing out a concept, I don't have much other code. The only static variable I have, is the one in the GameState class :

class
GameState extends FlxState
{
   public static var game:GameState;
   ....

   override public function create():Void
   {
     super.create();
     game = this;
  }
   
...
}



I use it in the 2 View classes to call a method from the class GameState.


class
View_Test1 extends FlxGroup
{
   ...
   private function gotoTest2():Void
   
{
     
GameState.game.switchToView("View_Test2", View_Test2);
   
}
   
...
}


(See code in my first post)
If I start up the program > set the first counter to 1 > switch view > set second counter to 2 > go back to 1st view > counter is 0 > set counter to 3 > go back to 2nd view > counter is still 2 > go back to 1st view > counter is still 3 ???


Sam Bellman

unread,
Apr 19, 2016, 6:39:51 AM4/19/16
to haxef...@googlegroups.com
I basically copied and pasted your code into an empty project and it works as expected. When you are creating your View_Test1 for the first time, how are you doing it and is the newView string definitely the same as what it being called in View_Test2?

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/fvL7k3AAAsk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.
Visit this group at https://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/7b269c8b-28a1-4fbc-b62c-e253e11a0d75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s c

unread,
Apr 19, 2016, 6:51:13 AM4/19/16
to haxef...@googlegroups.com
Sam,

You're THE BEST ! ☺

" ... and is the newView string definitely the same as what it being called in View_Test2?"

One capitalized letter makes all the difference !

It's a stupid mistake, but I would not have found it on my own. Being new to HaxeFlixel, I wasn't even sure if my code was supposed to work or not ...

Sam Bellman

unread,
Apr 19, 2016, 7:02:57 AM4/19/16
to haxef...@googlegroups.com
And this is why we use constants :D

Glad to help. On places to ask for help, as slow as it can be this place is probably still the best for Haxeflixel related questions. For language or other haxe related stuff try the haxe google group. The openfl forums are a fair bit busier so they can also be good.

Reply all
Reply to author
Forward
0 new messages