jetlag2d
    Preparing search index...

    Class Stage

    Stage is the container for all of the functionality for the playable portion of a game. Stage has several components:

    • The world, where all the action of the game happens
    • The heads-up display (HUD), where the user interface of the game is drawn.
    • The Score object
    • The background music and background color
    • The background and foreground parallax layers
    • The code for building, managing, and dismissing the win/lose/pause/welcome scenes

    Stage is effectively a singleton: On any transition from one stage to another in the game, we don't make a new Stage object... instead we clear out the existing one and reuse it.

    Stage does not manage transitions between scenes on its own. Instead, it has mechanisms (onScreenChange and endLevel) for resetting itself at the beginning of a stage, and cleaning itself up at the end of a stage.

    Index
    accelerometer: AccelerometerDevice

    access to the the device's accelerometer

    background: ParallaxSystem

    The background layers

    backgroundColor: string = "#ffffff"

    Background color for the stage being drawn. Defaults to white

    The game-wide configuration object

    console: ConsoleDevice

    A console device, for debug messages

    foreground: ParallaxSystem

    The foreground layers

    gameMusic: MusicLayers = ...

    Named layers of background music that don't stop when the level changes

    gamepads: GamepadDevice[] = ...

    Up to four gamepad slots, matching navigator.getGamepads()'s indices. Each entry always exists (check .connected before using one), so stage.gamepads[0] never throws even if nothing's plugged in yet.

    gestures: GestureDevice

    touch controller, providing gesture inputs

    hud: Scene

    A heads-up display

    imageLibrary: ImageLibraryService = ...

    A library of images

    keyboard: KeyboardDevice = ...

    keyboard controller, providing key event inputs

    levelMusic: MusicLayers = ...

    Named layers of music that belong to one level. Every layer is stopped and emptied when the level changes.

    musicLibrary: AudioLibraryService

    A library of sound and music files

    network: NetworkDevice = ...

    Network interface

    The current overlay (pause/win/lose) scene, if any

    platform: PlatformDevice

    Platform-specific features * *

    random: RandomService = ...

    A random number generator, for reproducible randomness

    renderer: RendererDevice

    rendering support, for drawing to the screen

    score: ScoreService = ...

    The Score, suitable for use throughout JetLag

    speech: TextToSpeechDevice = ...

    Text-to-speech support

    storage: StorageDevice

    Persistent storage + volatile storage for a game session and a level

    The tilt system for the stage

    timeScale: number = 1

    How fast the world runs: 1 is normal, 0.5 is half speed, and 0 freezes it. This slows physics, timers, and animations, but not the HUD or overlays. See slowMotion and hitstop for changing it for a short time.

    visibility: VisibilityDevice = ...

    Page visibility detection support

    The physics world in which all actors exist

    • Freeze the world for a moment, such as when a heavy blow lands. The camera (shake) and the HUD keep going.

      Parameters

      • seconds: number

        How long to freeze, in real seconds

      Returns void

    • Update every gamepad slot from the browser's live gamepad state, and fire any button handlers whose pressed state changed

      Returns void

    • This code is called dozens of times per second to update the game's world's state and re-draw the world

      Parameters

      • realElapsedMs: number

        The time in milliseconds since the previous render

      Returns void

    • Request that an overlay be put on top of the game. This is not the HUD. It's something that goes on top of everything else, and prevents the game from playing, such as a pause scene, a win/lose scene, or a welcome scene.

      Parameters

      • builder: (overlay: Scene) => void

        Code for creating the overlay. When requestScreenshot is true, it is also given the screenshot

      • OptionalrequestScreenshot: false

        Should the overlay delay for a cycle or two, so a screenshot can be taken first? (Default false)

      Returns void

    • Request that an overlay be put on top of the game. This is not the HUD. It's something that goes on top of everything else, and prevents the game from playing, such as a pause scene, a win/lose scene, or a welcome scene.

      Parameters

      • builder: (overlay: Scene, screenshot: ImageSprite) => void

        Code for creating the overlay. When requestScreenshot is true, it is also given the screenshot

      • requestScreenshot: true

        Should the overlay delay for a cycle or two, so a screenshot can be taken first? (Default false)

      Returns void

    • Run the world slowly for a short time, and then at normal speed again.

      Parameters

      • seconds: number

        How long it lasts, in real seconds

      • scale: number

        How fast the world runs while it lasts: 0.25 is a quarter of normal speed

      Returns void

    • Before we call programmer code to load a new stage, we call this to ensure that everything is in a clean state.

      Parameters

      • builder: () => void

      Returns void