View source

class flaxen.system.ModeSystem extends FlaxenSystem

Available on all platforms

In charge of maintenance of transitions between game modes.

To change modes, use flaxen.setMode(NewMode); NewMode is one of the ApplicationModeTypes listed in Application.hx. For example:

flaxen.setMode(Mode("MyMode")); // switch to custom mode flaxen.setMode(Play); // switch to built-in mode

When a transition is detected, the stop handler for the current mode is called, unprotected entities are destroyed, and then the start handler for the new mode is called.

Start Handler - registerStartHandler

Put your mode initialization in this function. This is where you create new entities, for example. Changing flaxen.getApp().nextMode during this handler will cause an immediate transition to another mode. You might use this, for example, in the Init handler, to immediately transition to the Menu mode without delay.

Update Handler - registerUpdateHandler The UpdateSystem invokes a callback every time the app is updated. This is intended to provide you with a place to process player inputs, but it can do any kind of frequently-called work.

Stop Handler - registerStopHandler

Before unprotected entities have been removed the stop handler is called. You could use this to save game state to an external source before the entities are flushed, for instance. You can force transition to a different following mode by setting flaxen.getApp().nextMode to a different mode.

If the Always mode is supplied, this mode is executed when starting or stopping ALL modes. The Always handler is called AFTER the main handler is called. Also see Transitional.

Instance Fields

function new(f:Flaxen):Void

function init():Void

function registerHandler(handler:FlaxenHandler, ?mode:ApplicationMode):Void

function registerStopHandler(handler:ModeCallback, mode:ApplicationMode):Void

function registerUpdateHandler(handler:ModeCallback, ?mode:ApplicationMode):Void

function removeUnprotected(mode:ApplicationMode):Void

Remove all entities, excepting those that are protected. An entity is protected if it has a Transitional component marked "Always" or if the Transitional mode is the same as the mode we're transitioning to.

  • TODO Jive this with Flaxen.removeTransitionedEntities();

function update(time:Float):Void