Class Game

Hierarchy

  • Game

Constructors

Properties

_deltaTime: number = 0
_isLoadedAllResources: boolean = false
_isPlaying: boolean = false
_signals: Signals = ...
_tempMouseWheelDeltaY: number = 0
_unscaledTime: number = 0
canvas: HTMLCanvasElement
canvasViewOffset: Vector2
gameObjects: GameObject[] = []

Sorted game object array

gameSettings: GameSettings
grid: Vector2
input: Input
isNeedToUpdate: boolean = true
lastMouseHoveredGameObject: undefined | ClickableGameObject
renderer: Renderer = ...
resources: Map<string, Resource> = ...
timeScale: number = 1

Accessors

  • get isMousePrimaryButtonDown(): boolean
  • Use input.isMousePrimaryButtonDown instead.

    Deprecated

    since version 1.0.8

    Returns boolean

  • get mouseClientPos(): Vector2
  • Use input.mouseClientPosition instead.

    Deprecated

    since version 1.0.8

    Returns Vector2

  • get mousePos(): Vector2
  • Use input.mouseWorldPosition instead.

    Deprecated

    since version 1.0.8

    Returns Vector2

  • get mousePrecisePos(): Vector2
  • Use input.mousePreciseWorldPosition instead.

    Deprecated

    since version 1.0.8

    Returns Vector2

Methods

  • Adds unique game object to game.

    Method

    Returns

    The added game object

    Example

    game.AddGameObject(new JSGL.GameObject());
    

    Parameters

    Returns GameObject

  • Creates HTMLImageElement from path.

    Method

    Returns

    The image element

    Example

    game.CreateImage('./resources/img/player.png');
    

    Parameters

    • path: string

      The image path

    Returns HTMLImageElement

  • Destroys existed game object by unique id

    Method

    Example

    game.DestroyGameObjectById('51870300-4187221613-3012590175-3461657014');
    

    Parameters

    • id: string

      The unique id

    Returns void

  • Destroys existed game object by index in game objects array

    Method

    Example

    game.DestroyGameObjectByIndex(0);
    

    Parameters

    • index: number

      The index

    Returns void

  • Destroys existed game object by reference

    Method

    Example

    const gameObject = ...
    game.DestroyGameObjectByRef(gameObject);

    Parameters

    • gameObject: GameObject

      The game object reference

    Returns void

  • Gets game object by unique id.

    Method

    Returns

    The game object

    Example

    game.GetGameObjectById('51870300-4187221613-3012590175-3461657014');
    

    Parameters

    • id: string

      The unique id

    Returns undefined | GameObject

  • Gets all existed game objects by given name.

    Method

    Returns

    Array of game objects with given name.

    Example

    game.GetGameObjectsByName('exampleName');
    

    Parameters

    • name: string

      The name.

    Returns GameObject[]

  • Gets all existed game objects by given tag.

    Method

    Returns

    The array of game objects with given tag.

    Example

    game.GetGameObjectsByTag('exampleTag');
    

    Parameters

    • tag: string

      The - tag.

    Returns GameObject[]

  • Gets all existed game objects with type equal to param.

    Returns

    Array of selected game objects

    Example

    game.GetGameObjectsByType(JSGL.Shape);
    

    Parameters

    • type: object

      The type

    Returns GameObject[]

  • Gets the image resource by unique resource key.

    Method

    Returns

    The image

    Example

    const image = game.GetImage('player');
    

    Parameters

    • uid: string

      The unique resource key.

    Returns undefined | object

  • Gets the resource by unique resource key.

    Method

    Returns

    The resource

    Example

    const resource = game.GetResource('player');
    

    Parameters

    • uid: string

      The unique resource key.

    Returns Resource

  • Starts loading all resources which is not loaded. Emits GameEvent at loadAllResources channel.

    Returns void

  • Starts loading game resources and returns promise.

    Method

    Returns

    The Promise

    Example

    game.LoadGameAndStart().then((e) => {
    console.log('Game sucessfully loaded!');
    }).catch((error) => {
    console.error('Error');
    }).finally(() => {
    console.log("Finally");
    });

    Returns Promise<GameEvent>

  • Loads resource with resource manager.

    Method

    Example

    game.LoadResource('image', 'player', './resources/img/player.png');
    

    Parameters

    • type: "image"

      The resource type

    • uid: string

      The resource unique key

    • path: string

      The resource path

    Returns void

  • Plays sound at the page.

    Method

    Example

    game.PlaySound('./resources/sounds/death.mp3', false, 0.8);
    

    Parameters

    • path: string

      The path to sound file

    • loop: boolean = false

      is looped?

    • volume: number = 1

      The volume decimal midpoint

    Returns void

  • Scaling canvas size on page to percentage of parent element.

    Returns

    The final canvas size

    Parameters

    • percentage: number

      The decimal midpoint

    Returns Vector2

  • Sorts all game objects by sorting order property.

    Returns void

  • Starts the game loop and emit start (GameEvent) event.

    Returns void

  • Starts new game loop

    Returns void

  • WARNING! Stops the game loop

    Returns void

  • Tells the game it needs to be redrawn. Call it when some visible objects has been changed.

    Returns void

  • Parameters

    • time: number

    Returns void

  • Returns void

  • Parameters

    • time: number

    Returns void

  • Returns void

  • Parameters

    • game: Game
    • event: MouseEvent

    Returns void

  • Parameters

    • game: Game
    • event: WheelEvent

    Returns void

  • Appends listener to event channel.

    Method

    Example

    game.on('channel', () => { console.log('received!') });
    

    Parameters

    • channel: string

      The listener event channel.

    • callback: ((event: GameEvent) => void)

      Executed function after receiving a signal on given channel.

    Returns void