Function set

  • associate the specified state with a Stage

    Parameters

    • state: number

      State ID (see constants)

    • stage: Stage

      Instantiated Stage to associate with state ID

    • Optionalstart: boolean = false

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

    Returns void

    set

    state

    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());