Dispatching Signals with HaxeFlixel

ShaunHaxe0 Comments

Haxe C++ target

When the play button is pressed, I don’t want it to switch state in the context of the button like seen below, but in a function contained in the Main Menu state, this gives me more control of other components, such as a bringing up a loading screen while the state switches.

I found on an Android device, switching state there is a 2-3 second pause as it prepares the next screen. I wanted to pull up a loading icon so it doesn’t look like the game has crashed.

First off, I pass in a new argument when creating a new instance of the button called: callback with the option to pass a string value.

In my state screen I pass an anonymous function.

I then register the signal by calling addSubscriber. This will create the signal if it doesn’t exist.

Now in the play button I dispatch the signal on mouse up. This is then caught in the state screen, and from there I can do what I need to do.



Leave a Reply

Your email address will not be published. Required fields are marked *