state

namespace state

a State Manager (state machine)

Public Properties


CREDITS state.js:200
static CREDITS: number = 7

number

default state ID for Credits Stage

DEFAULT state.js:216
static DEFAULT: number = 9

number

default state ID for the default Stage (the default stage is the one running as soon as melonJS is started)

GAME_END state.js:184
static GAME_END: number = 5

number

default state ID for Game End Stage

GAMEOVER state.js:176
static GAMEOVER: number = 4

number

default state ID for Game Over Stage

LOADING state.js:144
static LOADING: number = 0

number

default state ID for Loading Stage

PLAY state.js:168
static PLAY: number = 3

number

default state ID for Play Stage

READY state.js:160
static READY: number = 2

number

default state ID for "Ready" Stage

SCORE state.js:192
static SCORE: number = 6

number

default state ID for High Score Stage

SETTINGS state.js:208
static SETTINGS: number = 8

number

default state ID for Settings Stage

USER state.js:225
static USER: number = 100

number

default state ID for user defined constants

let STATE_INFO = me.state.USER + 0;
let STATE_WARN = me.state.USER + 1;
let STATE_ERROR = me.state.USER + 2;
let STATE_CUTSCENE = me.state.USER + 3;

Public Methods


change state.js:475
change(state: number, forceChange: boolean, args: unknown) → {}

change the game/app state

// 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);
Parameters:
Name Type Attributes Description
state number

State ID (see constants)

forceChange boolean

if true the state will be changed immediately

args unknown

<optional>

extra arguments to be passed to the reset functions

current state.js:435
current() → {Stage}

return a reference to the current stage
useful to call a object specific method

Returns:
Type Description
Stage
isCurrent state.js:528
isCurrent(state: number) → {boolean}

return true if the specified state is the current one

Parameters:
Name Type Description
state number

State ID (see constants)

Returns:
Type Description
boolean

true if the specified state is the current one

isPaused state.js:348
isPaused() → {boolean}

Return the pause state of the state manager

Returns:
Type Description
boolean

true if the game is paused

isRunning state.js:337
isRunning() → {boolean}

return the running state of the state manager

Returns:
Type Description
boolean

true if a "process is running"

pause state.js:264
pause(music: boolean) → {}

pause the current stage

Parameters:
Name Type Attributes Default Description
music boolean

<optional>

false

pause current music track on screen pause

restart state.js:289
restart(music: boolean) → {}

Restart the current stage from a full stop.

Parameters:
Name Type Attributes Default Description
music boolean

<optional>

false

resume current music track on screen resume

resume state.js:313
resume(music: boolean) → {}

resume the current stage

Parameters:
Name Type Attributes Default Description
music boolean

<optional>

false

resume current music track on screen resume

set state.js:359
set(state: number, stage: Stage, start : boolean) → {}

associate the specified state with a Stage

 class MenuButton extends me.GUI_Object {
     onClick() {
         // Change to the PLAY state when the button is clicked
         me.state.change(me.state.PLAY);
         return true;
     }
 };

 class MenuScreen extends me.Stage {
     onResetEvent() {
         // 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() {
         // Stop music
         me.audio.stopTrack();
     }
 };

 me.state.set(me.state.MENU, new MenuScreen());
Parameters:
Name Type Attributes Default Description
state number

State ID (see constants)

stage Stage

Instantiated Stage to associate with state ID

start boolean

<optional>

false

if true the state will be changed immediately after adding it.

set state.js:417
set(state: number) → {Stage}

returns the stage associated with the specified state (or the current one if none is specified)

Parameters:
Name Type Attributes Description
state number

<optional>

State ID (see constants)

Returns:
Type Description
Stage
setTransition state.js:463
setTransition(state: number, enable: boolean) → {}

enable/disable the transition to a particular state (by default enabled for all)

Parameters:
Name Type Description
state number

State ID (see constants)

enable boolean
stop state.js:238
stop(pauseTrack: boolean) → {}

Stop the current stage.

Parameters:
Name Type Attributes Default Description
pauseTrack boolean

<optional>

false

pause current track on screen stop.

transition state.js:447
transition(effect: string, color: Color | string, duration: number) → {}

specify a global transition effect

Parameters:
Name Type Attributes Default Description
effect string

(only "fade" is supported for now)

color Color | string

a CSS color value

duration number

<optional>

1000

expressed in milliseconds


Powered by webdoc!