Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TileMap

The TileMap class provides a lightweight way to do large complex scenes with collision without the overhead of actors.

Hierarchy

  • TileMapImpl
    • TileMap

Implements

Index

Constructors

constructor

  • new TileMap(config: TileMapArgs): TileMap
  • new TileMap(x: number, y: number, cellWidth: number, cellHeight: number, rows: number, cols: number): TileMap

Properties

active

active: boolean = true

Whether this entity is active, if set to false it will be reclaimed

cellHeight

cellHeight: number

cellWidth

cellWidth: number

changes

changes: Observable<AddedComponent | RemovedComponent> = new Observable<AddedComponent | RemovedComponent>()

Observable that keeps track of component add or remove changes on the entity

cols

cols: number

components

components: ComponentMapper<KnownComponents> = new Proxy<ComponentMapper<KnownComponents>>({} as any, this._handleChanges)

Dictionary that holds entity components

data

data: Cell[] = []

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

id

id: number = Entity._ID++

The unique identifier for the entity

isOffscreen

isOffscreen: boolean = false

logger

logger: Logger = Logger.getInstance()

rotation

rotation: number = 0

rows

rows: number

scale

scale: Vector = Vector.One

visible

visible: boolean = true

x

x: number

y

y: number

z

z: number = 0

Accessors

isInitialized

  • get isInitialized(): boolean

pos

tags

  • get tags(): string[]

types

  • get types(): string[]

Methods

_initialize

  • _initialize(engine: Engine): void

_postupdate

  • _postupdate(engine: Engine, delta: number): void

_preupdate

  • _preupdate(engine: Engine, delta: number): void

addComponent

clone

collides

  • Returns the intersection vector that can be used to resolve collisions with actors. If there is no collision null is returned.

    Parameters

    Returns Vector

debugDraw

  • debugDraw(ctx: CanvasRenderingContext2D): void
  • Draws all the tile map's debug info. Called by the Scene.

    Parameters

    • ctx: CanvasRenderingContext2D

      The current rendering context

    Returns void

draw

  • draw(ctx: CanvasRenderingContext2D, delta: number): void
  • Draws the tile map to the screen. Called by the Scene.

    Parameters

    • ctx: CanvasRenderingContext2D

      The current rendering context

    • delta: number

      The number of milliseconds since the last draw

    Returns void

emit

  • emit(eventName: string, eventObject: GameEvent<any>): void

getCell

  • getCell(x: number, y: number): Cell

getCellByIndex

  • getCellByIndex(index: number): Cell

getCellByPoint

  • getCellByPoint(x: number, y: number): Cell
  • Returns the Cell by testing a point in global coordinates, returns null if no cell was found.

    Parameters

    • x: number
    • y: number

    Returns Cell

has

  • has(type: string): boolean

hasTag

  • hasTag(tag: string): boolean

isKilled

  • isKilled(): boolean

kill

  • kill(): void

off

  • off(eventName: string, handler?: function): void
  • Alias for removeEventListener. If only the eventName is specified it will remove all handlers registered for that specific event. If the eventName and the handler instance are specified only that handler will be removed.

    Parameters

    • eventName: string

      Name of the event to listen for

    • Optional handler: function

      Event handler for the thrown event

    Returns void

on

  • on(eventName: Events.preupdate, handler: function): void
  • on(eventName: Events.postupdate, handler: function): void
  • on(eventName: Events.predraw, handler: function): void
  • on(eventName: Events.postdraw, handler: function): void
  • on(eventName: string, handler: function): void

onInitialize

  • onInitialize(_engine: Engine): void

onPostUpdate

  • onPostUpdate(_engine: Engine, _delta: number): void

onPreUpdate

  • onPreUpdate(_engine: Engine, _delta: number): void

once

  • once(eventName: string, handler: function): void
  • Once listens to an event one time, then unsubscribes from that event

    Parameters

    • eventName: string

      The name of the event to subscribe to once

    • handler: function

      The handler of the event that will be auto unsubscribed

    Returns void

registerSpriteSheet

  • registerSpriteSheet(key: string, spriteSheet: SpriteSheet): void

removeComponent

  • Removes a component from the entity, by default removals are deferred to the end of entity processing to avoid consistency issues

    Components can be force removed with the force flag, the removal is not deferred and happens immediately

    Type parameters

    Parameters

    • componentOrType: ComponentOrType
    • Default value force: boolean = false

    Returns Entity<ExcludeType<TransformComponent | CanvasDrawComponent, ComponentOrType>>

update

  • update(engine: Engine, delta: number): void