What is the equivalent of FlxState in Heaps.io ?

The Heaps.io library is a great gamedev tool for both 2d and 3d projects, however, the documentation is severely lacking at the time of writing this blogpost. It took me a while to find the answer to the question in the title, so I wanted to share this with you here, in the hope to help some other people who are searching for how to manage state in Heaps.io like in Haxeflixel on the Internet.

In HaxeFlixel there is the FlxState class which you can use to control the state and scene of your game. There is something in similar in Heaps.io.

import flixel.FlxState;
import flixel.FlxG;

class StartState extends FlxState
{
    override public function create():Void
    {
        super.create();

        // Go to menu state
        FlxG.switchState(new MenuState());
    }

    override public function update( elapsed:Float ):Void 
    {
        super.update(elapsed);
    }
}

Below you can see how you would achieve more or less the same in Heaps.io. Please note that the two game engines are different, so there are differences in the features provided by each class.

// Extend hxd.App instead of FlxState.
class StartApp extends hxd.App 
{
    // Use init() instead of create().
    override public function init() 
    {
        super.init();

        // You can switch 'App' like you would switch a FlxState.
        new MenuApp().setCurrent();
    }

    // The update function works the same.
    override public function update( elapsed:Float ) 
    {
        super.update(elapsed);
    }
}

There is this post in the Heaps.io community forum which gives some insight as well into several other properties of FlxState that work differently in Heaps.io, but it does not state explicitely that hxd.App works similar to FlxState.

Leave a comment

Your email address will not be published.