Namespace: state

me. state

a State Manager (state machine)

There is no constructor function for me.state.

Source:
state.js, line 12

Members

<static, constant> CREDITS

default state ID for Credits Screen
Source:
state.js, line 213

<static, constant> GAME_END

default state ID for Game End Screen
Source:
state.js, line 197

<static, constant> GAMEOVER

default state ID for Game Over Screen
Source:
state.js, line 189

<static, constant> LOADING

default state ID for Loading Screen
Source:
state.js, line 157
default state ID for Menu Screen
Source:
state.js, line 165

<static, constant> PLAY

default state ID for Play Screen
Source:
state.js, line 181

<static, constant> READY

default state ID for "Ready" Screen
Source:
state.js, line 173

<static, constant> SCORE

default state ID for High Score Screen
Source:
state.js, line 205

<static, constant> SETTINGS

default state ID for Settings Screen
Source:
state.js, line 221

<static, constant> USER

default state ID for user defined constants
Source:
state.js, line 229
Example
var STATE_INFO = me.state.USER + 0;
var STATE_WARN = me.state.USER + 1;
var STATE_ERROR = me.state.USER + 2;
var STATE_CUTSCENE = me.state.USER + 3;

Methods

<static> change(state)

change the game/app state
Parameters:
Name Type Argument Description
state Number State ID (see constants)
arguments... <optional>
extra arguments to be passed to the reset functions
Source:
state.js, line 525
Example
// The onResetEvent method on the play screen will receive two args:
// "level_1" and the number 3
me.state.change(me.state.PLAY, "level_1", 3);

<static> current() → {me.Stage}

return a reference to the current screen object
useful to call a object specific method
Source:
state.js, line 482
Returns:
Type
me.Stage

<static> isCurrent(state)

return true if the specified state is the current one
Parameters:
Name Type Description
state Number State ID (see constants)
Source:
state.js, line 577

<static> isPaused() → {Boolean}

Return the pause state of the state manager
Source:
state.js, line 415
Returns:
true if the game is paused
Type
Boolean

<static> isRunning() → {Boolean}

return the running state of the state manager
Source:
state.js, line 403
Returns:
true if a "process is running"
Type
Boolean

<static> onPause()

onPause callback
Source:
state.js, line 242

<static> onRestart()

onRestart callback
Source:
state.js, line 266

<static> onResume()

onResume callback
Source:
state.js, line 250

<static> onStop()

onStop callback
Source:
state.js, line 258

<static> pause(pauseTrack)

pause the current screen object
Parameters:
Name Type Description
pauseTrack Boolean pause current track on screen pause
Source:
state.js, line 312

<static> restart(resumeTrack)

Restart the screen object from a full stop.
Parameters:
Name Type Description
resumeTrack Boolean resume current track on screen resume
Source:
state.js, line 342

<static> resume(resumeTrack)

resume the screen object
Parameters:
Name Type Description
resumeTrack Boolean resume current track on screen resume
Source:
state.js, line 374

<static> set(state, stage)

associate the specified state with a Stage
Parameters:
Name Type Description
state Number State ID (see constants)
stage me.Stage Instantiated Stage to associate with state ID
Source:
state.js, line 427
Example
var MenuButton = me.GUI_Object.extend({
    "onClick" : function () {
        // Change to the PLAY state when the button is clicked
        me.state.change(me.state.PLAY);
        return true;
    }
});

var MenuScreen = me.Stage.extend({
    onResetEvent: function() {
        // Load background image
        me.game.world.addChild(
            new me.ImageLayer(0, 0, {
                image : "bg",
                z: 0 // z-index
            }
        );

        // Add a button
        me.game.world.addChild(
            new MenuButton(350, 200, { "image" : "start" }),
            1 // z-index
        );

        // Play music
        me.audio.playTrack("menu");
    },

    "onDestroyEvent" : function () {
        // Stop music
        me.audio.stopTrack();
    }
});

me.state.set(me.state.MENU, new MenuScreen());

<static> setTransition(state, enable)

enable/disable transition for a specific state (by default enabled for all)
Parameters:
Name Type Description
state Number State ID (see constants)
enable Boolean
Source:
state.js, line 512

<static> stop(pauseTrack)

Stop the current screen object.
Parameters:
Name Type Description
pauseTrack Boolean pause current track on screen stop.
Source:
state.js, line 282

<static> transition(effect, color, duration)

specify a global transition effect
Parameters:
Name Type Argument Default Description
effect String (only "fade" is supported for now)
color me.Color | String a CSS color value
duration Number <optional>
1000 expressed in milliseconds
Source:
state.js, line 495