Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GameState

Basic state of the game state machine. This is the base of the whole game

Hierarchy

Index

Constructors

constructor

  • Constructs a new state with the given id

    Parameters

    • key: any

      The id of the state. We use ids to refer to states because otherwise we get circular references

    Returns GameState

Methods

cancelAllAsyncOperations

  • cancelAllAsyncOperations(): void
  • Cancels all promises on the api as well as our async channel

    Returns void

getDivElement

  • getDivElement(): HTMLElement
  • Returns the html element of the state

    Returns HTMLElement

getHasFadeIn

  • getHasFadeIn(): boolean
  • Should return whether to fade in the game state. This will then apply the right css classes for the fadein.

    Returns boolean

getHasFadeOut

  • getHasFadeOut(): boolean
  • Should return whether to fade out the game state. This will then apply the right css classes for the fadeout and wait the delay before moving states

    Returns boolean

getHasUnloadConfirmation

  • getHasUnloadConfirmation(): boolean
  • Returns if the state has an unload confirmation, this is the "Are you sure you want to leave the page" message.

    Returns boolean

getInOutFadeTime

  • getInOutFadeTime(): 0 | 200
  • Should return how many mulliseconds to fade in / out the state. Not recommended to override!

    Returns 0 | 200

    Time in milliseconds to fade out

getInnerHTML

  • getInnerHTML(): string
  • Should return the html code of the state.

    Returns string

getKey

  • getKey(): any
  • Returns the states key

    Returns any

getPauseOnFocusLost

  • getPauseOnFocusLost(): boolean
  • Returns if this state should get paused if it does not have focus

    Returns boolean

    true to pause the updating of the game

getThemeMusic

  • getThemeMusic(): string
  • Should return the theme music for this state

    Returns string

internalCleanUpClickDetectors

  • internalCleanUpClickDetectors(): void
  • Cleans up all click detectors

    Returns void

internalEnterCallback

  • internalEnterCallback(payload: any, callCallback?: boolean): void
  • Internal callback when entering the state. Do not override!

    Parameters

    • payload: any

      Arbitrary data passed from the state which we are transferring from

    • Default value callCallback: boolean = true

      Whether to call the onEnter callback

    Returns void

internalGetFadeInOutTime

  • internalGetFadeInOutTime(): number
  • Internal method to compute the time to fade in / out

    Returns number

    time to fade in / out in ms

internalGetFullHtml

  • internalGetFullHtml(): string
  • Internal method to get the HTML of the game state.

    Returns string

internalLeaveCallback

  • internalLeaveCallback(): void
  • Internal callback when the state is left. Do not override!

    Returns void

internalOnAppPauseCallback

  • internalOnAppPauseCallback(): void
  • Internal app pause callback

    Returns void

internalOnAppResumeCallback

  • internalOnAppResumeCallback(): void
  • Internal app resume callback

    Returns void

internalOnBeforeExitCallback

  • internalOnBeforeExitCallback(): void
  • Internal callback before the state is left. Also is called on page unload

    Returns void

internalRegisterCallback

  • internalRegisterCallback(stateManager: any, app: any): void
  • Internal callback from the manager. Do not override!

    Parameters

    • stateManager: any
    • app: any

    Returns void

moveToState

  • moveToState(stateKey: any, payload?: object, skipFadeOut?: boolean): void
  • Transfers to a new state

    Parameters

    • stateKey: any

      The id of the new state

    • Default value payload: object = {}
    • Default value skipFadeOut: boolean = false

    Returns void

mpHandleConnectionClose

  • mpHandleConnectionClose(): void
  • Should handle a closed multiplayer connection

    Returns void

mpHandlePacket

  • mpHandlePacket(packet: any): boolean
  • Should handle a multiplayer packet and return true if the packet was handled and processed

    Parameters

    • packet: any

    Returns boolean

onAppPause

  • onAppPause(): void
  • Callback when the app got paused (on android, this means in background)

    Returns void

onAppResume

  • onAppResume(): void
  • Callback when the app got resumed (on android, this means in foreground again)

    Returns void

onBackButton

  • onBackButton(): void
  • Internal backbutton handler, called when the hardware back button is pressed or the escape key is pressed

    Returns void

onBackgroundTick

  • onBackgroundTick(dt: any): void
  • Background tick callback, called while the game is inactiev

    Parameters

    • dt: any

      Delta time in ms since last tick

    Returns void

onBeforeExit

  • onBeforeExit(): void
  • Callback before leaving the game state or when the page is unloaded

    Returns void

onEnter

  • onEnter(payload: any): void
  • Callback when entering the state, to be overriddemn

    Parameters

    • payload: any

      Arbitrary data passed from the state which we are transferring from

    Returns void

onLeave

  • onLeave(): void
  • Callback when leaving the state

    Returns void

onRender

  • onRender(dt: any): void
  • Render callback

    Parameters

    • dt: any

      Delta time in ms since last render

    Returns void

onResized

  • onResized(w: any, h: any): void
  • Called when the screen resized

    Parameters

    • w: any

      window/screen width

    • h: any

      window/screen height

    Returns void

showLanguageChooser

  • showLanguageChooser(dialogs: any, buttonSelector?: string): void
  • Shows a language chooser dialog

    Parameters

    • dialogs: any
    • Default value buttonSelector: string = "button.languageChoose"

    Returns void

trackClicks

  • trackClicks(element: any, handler: any, args?: object): void
  • Tracks clicks on a given element and calls the given callback on this state. If you want to call another function wrap it inside a lambda.

    Parameters

    • element: any

      The element to track clicks on

    • handler: any

      The handler to call

    • Default value args: object = {}

      Click detector arguments

    Returns void