Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GameMap

Phaser GameObject representing game map. It is the only visual element which is ever handler by Phaser in this project. The map can interact with the rest of the project by the injected Context object.

Hierarchy

  • GameObject
    • GameMap

Constructors

constructor

  • Parameters

    Returns GameMap

Properties

Private _itemsTimeout

_itemsTimeout: Timeout | undefined

Private _playersTimeout

_playersTimeout: Timeout | undefined

Private _terrainTimeout

_terrainTimeout: Timeout | undefined

active

active: boolean

The active state of this Game Object. A Game Object with an active state of true is processed by the Scenes UpdateList, if added to it. An active object is one which is having its logic and internal systems updated.

body

body: Body | StaticBody | MatterJS.BodyType

If this Game Object is enabled for Arcade or Matter Physics then this property will contain a reference to a Physics Body.

Private camera

camera: Camera

cameraFilter

cameraFilter: number

A bitmask that controls if this Game Object is drawn by a Camera or not. Not usually set directly, instead call Camera.ignore, however you can set this property directly using the Camera.id property:

Private center

center: Vector2 = XY(0, 0)

Private Readonly contexts

contexts: Contexts

Private currentAccount

currentAccount: Address

Private currentBlock

currentBlock: BlockInfo | undefined

data

data: DataManager

A Data Manager. It allows you to store, query and get key/value paired information specific to this Game Object. null by default. Automatically created if you use getData or setData or setDataEnabled.

ignoreDestroy

ignoreDestroy: boolean

This Game Object will ignore all calls made to its destroy method if this flag is set to true. This includes calls that may come from a Group, Container or the Scene itself. While it allows you to persist a Game Object across Scenes, please understand you are entirely responsible for managing references to and from this Game Object.

input

input: Phaser.Types.Input.InteractiveObject

If this Game Object is enabled for input then this property will contain an InteractiveObject instance. Not usually set directly. Instead call GameObject.setInteractive().

lastAnim

lastAnim: number = -1

Private layerCharacter

layerCharacter: DynamicTilemapLayer

Private layerGrass

layerGrass: StaticTilemapLayer

Private layerHighlight

layerHighlight: DynamicTilemapLayer

Private layerItems

layerItems: DynamicTilemapLayer

Private layerTerrain

layerTerrain: DynamicTilemapLayer

Private map

map: Tilemap

name

name: string

The name of this Game Object. Empty by default and never populated by Phaser, this is left for developers to use.

parentContainer

parentContainer: Container

The parent Container of this Game Object, if it has one.

renderFlags

renderFlags: integer

The flags that are compared against RENDER_MASK to determine if this Game Object will render or not. The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively. If those components are not used by your custom class then you can use this bitmask as you wish.

Protected scene

scene: Scene

The Scene to which this Game Object belongs. Game Objects can only belong to one Scene.

Private selectedTile

selectedTile: Tile | undefined

state

state: integer | string

The current state of this Game Object.

Phaser itself will never modify this value, although plugins may do so.

Use this property to track the state of a Game Object during its lifetime. For example, it could change from a state of 'moving', to 'attacking', to 'dead'. The state value should be an integer (ideally mapped to a constant in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons. If you need to store complex data about your Game Object, look at using the Data Component instead.

tabIndex

tabIndex: integer

The Tab Index of the Game Object. Reserved for future use by plugins and the Input Manager.

type

type: string

A textual representation of this Game Object, i.e. sprite. Used internally by Phaser but is available for your own custom classes to populate.

Private zoom

zoom: number = 1

Static Private Readonly CENTER

CENTER: Vector2 = XY((config.phaser.MAP_SIZE - 1) / 2,(config.phaser.MAP_SIZE - 1) / 2)

Static Readonly RENDER_MASK

RENDER_MASK: integer

The bitmask that GameObject.renderFlags is compared against to determine if the Game Object will render or not.

Methods

addListener

  • addListener(event: string | symbol, fn: Function, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: string | symbol

      The event name.

    • fn: Function

      The listener function.

    • Optional context: any

      The context to invoke the listener with. Default this.

    Returns this

Private animTerrain

  • animTerrain(): void
  • Function iterates over all tiles in terrain layer and character layer, and change their animation state if they are animated.

    Returns void

destroy

  • destroy(fromScene?: undefined | false | true): void
  • Destroys this Game Object removing it from the Display List and Update List and severing all ties to parent resources.

    Also removes itself from the Input Manager and Physics Manager if previously enabled.

    Use this to remove a Game Object from your game if you don't ever plan to use it again. As long as no reference to it exists within your own code it should become free for garbage collection by the browser.

    If you just want to temporarily disable an object then look at using the Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected.

    Parameters

    • Optional fromScene: undefined | false | true

      Is this Game Object being destroyed as the result of a Scene shutdown? Default false.

    Returns void

disableInteractive

  • disableInteractive(): this
  • If this Game Object has previously been enabled for input, this will disable it.

    An object that is disabled for input stops processing or being considered for input events, but can be turned back on again at any time by simply calling setInteractive() with no arguments provided.

    If want to completely remove interaction from this Game Object then use removeInteractive instead.

    Returns this

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol

      The event name.

    • Rest ...args: any[]

      Additional arguments that will be passed to the event handler.

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

getData

  • getData(key: string | string[]): any
  • Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist.

    You can also access values via the values object. For example, if you had a key called gold you can do either:

    sprite.getData('gold');

    Or access the value directly:

    sprite.data.values.gold;

    You can also pass in an array of keys, in which case an array of values will be returned:

    sprite.getData([ 'gold', 'armor', 'health' ]);

    This approach is useful for destructuring arrays in ES6.

    Parameters

    • key: string | string[]

      The key of the value to retrieve, or an array of keys.

    Returns any

getIndexList

  • getIndexList(): integer[]
  • Returns an array containing the display list index of either this Game Object, or if it has one, its parent Container. It then iterates up through all of the parent containers until it hits the root of the display list (which is index 0 in the returned array).

    Used internally by the InputPlugin but also useful if you wish to find out the display depth of this Game Object and all of its ancestors.

    Returns integer[]

getSelection

  • getSelection(): XY | undefined
  • Function returns world coordinates of the selected tile

    Returns XY | undefined

    Coordinates of currently selected tile or undefined, when there is no selected tile

Private getTileInfo

  • getTileInfo(tileX: integer, tileY: integer): Promise<TileInfo | undefined>
  • Function returning data about the tile on the given coordinates in tile space.

    Parameters

    • tileX: integer

      X coordinate in tile space

    • tileY: integer

      Y coordinate in tile space

    Returns Promise<TileInfo | undefined>

    Tile info or undefined when there is no tile on the given coordinates

Private getTileXYUnderCursor

  • getTileXYUnderCursor(): XY
  • Function transforming the current cursor position to the map coordinates in tile space.

    Returns XY

    Coordinates of tile under the cursor, in tile space

incData

  • incData(key: string | object, data?: any): this
  • Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0.

    If the Game Object has not been enabled for data (via setDataEnabled) then it will be enabled before setting the value.

    If the key doesn't already exist in the Data Manager then it is created.

    When the value is first set, a setdata event is emitted from this Game Object.

    Parameters

    • key: string | object

      The key to increase the value for.

    • Optional data: any

      The value to increase for the given key.

    Returns this

Private Readonly isTileVisible

  • isTileVisible(tileX: integer, tileY: integer): boolean
  • Function which decides whether the tile on the given tile coordinates is part of the currently rendered map region or not.

    Parameters

    • tileX: integer

      X coordinate in tile space

    • tileY: integer

      Y coordinate in tile space

    Returns boolean

    True if and only if the tile is currently rendered.

listenerCount

  • listenerCount(event: string | symbol): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

      The event name.

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

      The event name.

    Returns Function[]

moveSelection

  • moveSelection(deltaX: integer, deltaY: integer): void
  • Moves tile selection by deltaX tiles to the right and deltaY to the bottom.

    Parameters

    • deltaX: integer

      Number of tiles for moving the selection horizontally

    • deltaY: integer

      Number of tiles for moving the selection vertically

    Returns void

off

  • off(event: string | symbol, fn?: Function, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol

      The event name.

    • Optional fn: Function

      Only remove the listeners that match this function.

    • Optional context: any

      Only remove the listeners that have this context.

    • Optional once: undefined | false | true

      Only remove one-time listeners.

    Returns this

on

  • on(event: string | symbol, fn: Function, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: string | symbol

      The event name.

    • fn: Function

      The listener function.

    • Optional context: any

      The context to invoke the listener with. Default this.

    Returns this

Private Readonly onAccountChange

  • onAccountChange(account: Address): void
  • This function is called when the logged account is changed, and redraws players on the map

    Parameters

    • account: Address

      New logged account

    Returns void

Private Readonly onBlockChange

  • onBlockChange(block: BlockInfo | undefined): void
  • This function is called when there is newly mined block, and redraws spawned items on the map when it is necessary

    Parameters

    • block: BlockInfo | undefined

      New mined block

    Returns void

Private Readonly onMined

  • Function which is called whenever some player mined some resource. Then, the corresponding tile is changed from that resource to empty tile.

    Parameters

    • mined: MinedInfo

      Info about what player mined resource at what location

    • type: DataEventType

      Whether this info was added into database, changed in it or removed from it.

    Returns void

Private Readonly onPointerDown

  • onPointerDown(event: Pointer): void
  • Function which is called whenever there is a click event on the game canvas (except when there is a React popup over it), and selects the tile under the cursor as active.

    Parameters

    • event: Pointer

      Pointer event

    Returns void

Readonly onPointerMove

  • onPointerMove(event: Pointer): Promise<void>
  • Function which is called whenever the mouse moves over the game canvas, and emits corresponding event containing info about the tile under the cursor.

    Parameters

    • event: Pointer

      Pointer event

    Returns Promise<void>

Private Readonly onSeedChange

  • onSeedChange(): void
  • Whenever the game turn seed changes, this function is called and redraws map terrain and spawned items.

    Returns void

Private Readonly onZoom

  • onZoom(ev: WheelEvent): void
  • This function zooms or unzooms whole map on wheel event

    Parameters

    • ev: WheelEvent

      Wheel event

    Returns void

once

  • once(event: string | symbol, fn: Function, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: string | symbol

      The event name.

    • fn: Function

      The listener function.

    • Optional context: any

      The context to invoke the listener with. Default this.

    Returns this

preUpdate

  • preUpdate(time: number, delta: number): void
  • Parameters

    • time: number
    • delta: number

    Returns void

Private Readonly putTerrainAt

  • putTerrainAt(type: TerrainType, tileX: integer, tileY: integer): void
  • Function changes the terrain on given coordinates to the given type.

    Parameters

    • type: TerrainType

      New terrain type

    • tileX: integer

      X coordinate in tile space

    • tileY: integer

      Y coordinate in tile space

    Returns void

Private redrawAll

  • redrawAll(): void
  • This function redraws all layers of map.

    Returns void

Private redrawItems

  • redrawItems(): Promise<void>
  • Redraws item layer asynchronously.

    Returns Promise<void>

Private redrawItemsSync

  • redrawItemsSync(): Promise<void>
  • This function redraws the items layer by clearing it and then rendering spawned items on all coordinates where there currently should be spawned item. This method is very computation-heavy, so it waits (in a non-blocking way) every 128 tiles for 100 ms, so the rest of the app can respond.

    Returns Promise<void>

Private redrawPlayers

  • redrawPlayers(): Promise<void>
  • Redraws character layer asynchronously.

    Returns Promise<void>

Private redrawPlayersSync

  • redrawPlayersSync(): Promise<void>
  • This function redraws the character layer by clearing it and then rendering all the registered players on their locations.

    Returns Promise<void>

Private redrawTerrain

  • redrawTerrain(): Promise<void>
  • Redraws terrain layer asynchronously.

    Returns Promise<void>

Private redrawTerrainSync

  • redrawTerrainSync(): Promise<void>
  • This function first redraws the terrain layer based on the current game turn seed, then replace all the minable tiles with empty tiles when they have already been mined.

    Returns Promise<void>

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

      The event name.

    Returns this

removeInteractive

  • removeInteractive(): this
  • If this Game Object has previously been enabled for input, this will queue it for removal, causing it to no longer be interactive. The removal happens on the next game step, it is not immediate.

    The Interactive Object that was assigned to this Game Object will be destroyed, removed from the Input Manager and cleared from this Game Object.

    If you wish to re-enable this Game Object at a later date you will need to re-create its InteractiveObject by calling setInteractive again.

    If you wish to only temporarily stop an object from receiving input then use disableInteractive instead, as that toggles the interactive state, where-as this erases it completely.

    If you wish to resize a hit area, don't remove and then set it as being interactive. Instead, access the hitarea object directly and resize the shape being used. I.e.: sprite.input.hitArea.setSize(width, height) (assuming the shape is a Rectangle, which it is by default.)

    Returns this

removeListener

  • removeListener(event: string | symbol, fn?: Function, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol

      The event name.

    • Optional fn: Function

      Only remove the listeners that match this function.

    • Optional context: any

      Only remove the listeners that have this context.

    • Optional once: undefined | false | true

      Only remove one-time listeners.

    Returns this

setActive

  • setActive(value: boolean): this
  • Sets the active property of this Game Object and returns this Game Object for further chaining. A Game Object with its active property set to true will be updated by the Scenes UpdateList.

    Parameters

    • value: boolean

      True if this Game Object should be set as active, false if not.

    Returns this

setData

  • setData(key: string | object, data?: any): this
  • Allows you to store a key value pair within this Game Objects Data Manager.

    If the Game Object has not been enabled for data (via setDataEnabled) then it will be enabled before setting the value.

    If the key doesn't already exist in the Data Manager then it is created.

    sprite.setData('name', 'Red Gem Stone');

    You can also pass in an object of key value pairs as the first argument:

    sprite.setData({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 });

    To get a value back again you can call getData:

    sprite.getData('gold');

    Or you can access the value directly via the values property, where it works like any other variable:

    sprite.data.values.gold += 50;

    When the value is first set, a setdata event is emitted from this Game Object.

    If the key already exists, a changedata event is emitted instead, along an event named after the key. For example, if you updated an existing key called PlayerLives then it would emit the event changedata-PlayerLives. These events will be emitted regardless if you use this method to set the value, or the direct values setter.

    Please note that the data keys are case-sensitive and must be valid JavaScript Object property strings. This means the keys gold and Gold are treated as two unique values within the Data Manager.

    Parameters

    • key: string | object

      The key to set the value for. Or an object of key value pairs. If an object the data argument is ignored.

    • Optional data: any

      The value to set for the given key. If an object is provided as the key this argument is ignored.

    Returns this

setDataEnabled

  • setDataEnabled(): this
  • Adds a Data Manager component to this Game Object.

    Returns this

setInteractive

  • setInteractive(shape?: Phaser.Types.Input.InputConfiguration | any, callback?: Phaser.Types.Input.HitAreaCallback, dropZone?: undefined | false | true): this
  • Pass this Game Object to the Input Manager to enable it for Input.

    Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced input detection.

    If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific shape for it to use.

    You can also provide an Input Configuration Object as the only argument to this method.

    Parameters

    • Optional shape: Phaser.Types.Input.InputConfiguration | any

      Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.

    • Optional callback: Phaser.Types.Input.HitAreaCallback

      A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback.

    • Optional dropZone: undefined | false | true

      Should this Game Object be treated as a drop zone target? Default false.

    Returns this

setName

  • setName(value: string): this
  • Sets the name property of this Game Object and returns this Game Object for further chaining. The name property is not populated by Phaser and is presented for your own use.

    Parameters

    • value: string

      The name to be given to this Game Object.

    Returns this

Private setSelectedTile

  • setSelectedTile(tileX: integer, tileY: integer): Promise<void>
  • Most low-level method for selecting a tile. It should be called whenever the selection has changed. It receives the coordinates of the newly selected tile in tile space, then shifts the whole map when it is necessary to display the selected tile in center, unset the selection effect from the old tile and set it to the new tile. In the end, it emits the events related with selection

    Parameters

    • tileX: integer

      X coordinate of the newly selected tile, in tile space

    • tileY: integer

      Y coordinate of the newly selected tile, in tile space

    Returns Promise<void>

setSelection

  • setSelection(worldX: integer, worldY: integer): void
  • Changes tile selection to the given world coordinates.

    Parameters

    • worldX: integer

      X coordinate of the newly selected tile

    • worldY: integer

      Y coordinate of the newly selected tile

    Returns void

setState

  • setState(value: integer | string): this
  • Sets the current state of this Game Object.

    Phaser itself will never modify the State of a Game Object, although plugins may do so.

    For example, a Game Object could change from a state of 'moving', to 'attacking', to 'dead'. The state value should typically be an integer (ideally mapped to a constant in your game code), but could also be a string. It is recommended to keep it light and simple. If you need to store complex data about your Game Object, look at using the Data Component instead.

    Parameters

    • value: integer | string

      The state of the Game Object.

    Returns this

shutdown

  • shutdown(): void
  • Removes all listeners.

    Returns void

Private tileToWorld

  • tileToWorld(tileX: integer, tileY: integer): XY
  • Function for converting tile space coordinates to world space coordinates

    Parameters

    • tileX: integer

      X coordinate in tile space

    • tileY: integer

      Y coordinate in tile space

    Returns XY

    Equivalent coordinates in world space

toJSON

  • toJSON(): Phaser.Types.GameObjects.JSONGameObject
  • Returns a JSON representation of the Game Object.

    Returns Phaser.Types.GameObjects.JSONGameObject

toggleData

  • toggleData(key: string | object): this
  • Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false.

    If the Game Object has not been enabled for data (via setDataEnabled) then it will be enabled before setting the value.

    If the key doesn't already exist in the Data Manager then it is created.

    When the value is first set, a setdata event is emitted from this Game Object.

    Parameters

    • key: string | object

      The key to toggle the value for.

    Returns this

update

  • update(...args: any[]): void
  • To be overridden by custom GameObjects. Allows base objects to be used in a Pool.

    Parameters

    • Rest ...args: any[]

      args

    Returns void

willRender

  • willRender(camera: Camera): boolean
  • Compares the renderMask with the renderFlags to see if this Game Object will render or not. Also checks the Game Object against the given Cameras exclusion list.

    Parameters

    • camera: Camera

      The Camera to check against this Game Object.

    Returns boolean

Private worldToTile

  • worldToTile(worldX: integer, worldY: integer): XY
  • Function for converting world space coordinates to tile space coordinates

    Parameters

    • worldX: integer

      X coordinate in world space

    • worldY: integer

      Y coordinate in world space

    Returns XY

    Equivalent coordinates in tile space

Object literals

Readonly terrainMap

terrainMap: object

BARRIER

BARRIER: number = 4

COMMON

COMMON: number = 0

EMPTY

EMPTY: undefined = undefined

OBSTACLE

OBSTACLE: number = 3

RARE

RARE: number = 2

UNCOMMON

UNCOMMON: number = 1

Generated using TypeDoc