Skip to main content

Tile

TileMap Tile

A light-weight object that occupies a space in a collision map. Generally created by a [[TileMap]].

Tiles can draw multiple sprites. Note that the order of drawing is the order of the sprites in the array so the last one will be drawn on top. You can use transparency to create layers this way.

Hierarchy

Index

Constructors

constructor

Properties

publicactive

active: boolean = true

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

publicchildrenAdded$

childrenAdded$: Observable<Entity<any>> = ...

publicchildrenRemoved$

childrenRemoved$: Observable<Entity<any>> = ...

publiccomponentAdded$

componentAdded$: Observable<Component> = ...

publiccomponentRemoved$

componentRemoved$: Observable<Component> = ...

publicreadonlycomponents

components: Map<Function, Component> = ...

Current components on the entity

Do not modify

Use addComponent/removeComponent otherwise the ECS will not be notified of changes.

publicdata

data: Map<string, any> = ...

Arbitrary data storage per tile, useful for any game specific data

publicevents

events: EventEmitter<EntityEvents> = ...

Listen to or emit events for an entity

publicid

id: number = ...

The unique identifier for the entity

publicmap

map: TileMap

Reference to the TileMap this tile is associated with

publicname

name: string = ...

publicscene

scene: Scene<unknown> = null

The current scene that the entity is in, if any

publictagAdded$

tagAdded$: Observable<string> = ...

publictagRemoved$

tagRemoved$: Observable<string> = ...

publicreadonlyx

x: number

Integer x coordinate of the tile

publicreadonlyy

y: number

Integer y coordinate of the tile

Accessors

publicbounds

publiccenter

  • Tile position in world space


    Returns Vector

publicchildren

  • get children(): readonly Entity<any>[]
  • Get the direct children of this entity


    Returns readonly Entity<any>[]

publicdefaultGeometry

publicheight

  • get height(): number
  • Height of the tile in pixels


    Returns number

publicisInitialized

  • get isInitialized(): boolean
  • Gets whether the actor is Initialized


    Returns boolean

publicparent

  • Returns Entity<any>

publicpos

  • Return the world position of the top left corner of the tile


    Returns Vector

publicsolid

  • get solid(): boolean
  • set solid(val: boolean): void
  • Wether this tile should be treated as solid by the tilemap


    Returns boolean

  • Wether this tile should be treated as solid by the tilemap


    Parameters

    • val: boolean

    Returns void

publictags

  • get tags(): Set<string>
  • Specifically get the tags on the entity from [[TagsComponent]]


    Returns Set<string>

publictypes

  • The types of the components on the Entity


    Returns ComponentCtor[]

publicwidth

  • get width(): number
  • Width of the tile in pixels


    Returns number

Methods

publicaddChild

  • Adds an entity to be a child of this entity


    Parameters

    Returns Entity<any>

publicaddCollider

  • Adds a custom collider to the [[Tile]] to use instead of it's bounds

    If no collider is set but [[Tile.solid]] is set, the tile bounds are used as a collider.

    Note! the [[Tile.solid]] must be set to true for it to act as a "fixed" collider


    Parameters

    Returns void

publicaddComponent

  • addComponent<TComponent>(component: TComponent, force?: boolean): Entity<any>
  • Adds a component to the entity


    Type parameters

    Parameters

    • component: TComponent

      Component or Entity to add copy of components from

    • force: boolean = false

      Optionally overwrite any existing components of the same type

    Returns Entity<any>

publicaddGraphic

  • addGraphic(graphic: Graphic, options?: { offset?: Vector }): void
  • Add another [[Graphic]] to this TileMap tile


    Parameters

    Returns void

publicaddTag

  • addTag(tag: string): void
  • Adds a tag to an entity


    Parameters

    • tag: string

    Returns void

publicaddTemplate

  • addTemplate(templateEntity: Entity<any>, force?: boolean): Entity<any>
  • Adds a copy of all the components from another template entity as a "prefab"


    Parameters

    • templateEntity: Entity<any>

      Entity to use as a template

    • force: boolean = false

      Force component replacement if it already exists on the target entity

    Returns Entity<any>

publicclearColliders

  • clearColliders(): void
  • Clears all colliders from the [[Tile]]


    Returns void

publicclearComponents

  • clearComponents(): void
  • Returns void

publicclearGraphics

  • clearGraphics(): void
  • Clear all graphics from this tile


    Returns void

publicclone

  • Creates a deep copy of the entity and a copy of all its components


    Returns Entity<any>

publicemit

  • emit<TEventName>(eventName: TEventName, event: EntityEvents[TEventName]): void
  • emit(eventName: string, event?: any): void

publicflagDirty

  • flagDirty(): boolean
  • Returns boolean

get

publicgetAncestors

  • Returns a list of parent entities starting with the topmost parent. Includes the current entity.


    Returns Entity<any>[]

publicgetColliders

  • Returns the list of colliders


    Returns readonly Collider[]

publicgetComponents

  • Returns all component instances on entity


    Returns Component[]

publicgetDescendants

  • getDescendants(): Entity<any>[]
  • Returns a list of all the entities that descend from this entity. Includes the current entity.


    Returns Entity<any>[]

publicgetGraphics

  • Current list of graphics for this tile


    Returns readonly Graphic[]

publicgetGraphicsOffsets

  • getGraphicsOffsets(): readonly Vector[]
  • Current list of offsets for this tile's graphics


    Returns readonly Vector[]

publichas

  • Check if a component type exists


    Type parameters

    Parameters

    Returns boolean

hasAll

  • hasAll<TComponent>(requiredTypes: ComponentCtor<TComponent>[]): boolean
  • Verifies that an entity has all the required types


    Type parameters

    Parameters

    Returns boolean

hasAllTags

  • hasAllTags(requiredTags: string[]): boolean
  • Verifies that an entity has all the required tags


    Parameters

    • requiredTags: string[]

    Returns boolean

publichasTag

  • hasTag(tag: string): boolean
  • Check if a tag exists on the entity


    Parameters

    • tag: string

      name to check for

    Returns boolean

publicisKilled

  • isKilled(): boolean
  • Returns boolean

publickill

  • kill(): void
  • Kill the entity, means it will no longer be updated. Kills are deferred to the end of the update. If parented it will be removed from the parent when killed.


    Returns void

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void

publicon

publiconInitialize

  • onInitialize(engine: Engine<any>): void
  • onInitialize is called before the first update of the entity. This method is meant to be overridden.

    Synonymous with the event handler .on('initialize', (evt) => {...})


    Parameters

    Returns void

publiconPostUpdate

  • onPostUpdate(engine: Engine<any>, delta: number): void
  • Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('postupdate', (evt) =>{...})

    onPostUpdate is called directly after an entity is updated.


    Parameters

    • engine: Engine<any>
    • delta: number

    Returns void

publiconPreUpdate

  • onPreUpdate(engine: Engine<any>, delta: number): void
  • Safe to override onPreUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPreUpdate is called directly before an entity is updated.


    Parameters

    • engine: Engine<any>
    • delta: number

    Returns void

publiconce

publicremoveAllChildren

  • removeAllChildren(): Entity<any>
  • Removes all children from this entity


    Returns Entity<any>

publicremoveChild

  • Remove an entity from children if it exists


    Parameters

    Returns Entity<any>

publicremoveCollider

  • removeCollider(collider: Collider): void
  • Removes a collider from the [[Tile]]


    Parameters

    Returns void

publicremoveComponent

  • removeComponent<TComponent>(typeOrInstance: TComponent | ComponentCtor<TComponent>, force?: boolean): Entity<Exclude<any, TComponent>>
  • Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues

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


    Type parameters

    Parameters

    • typeOrInstance: TComponent | ComponentCtor<TComponent>
    • force: boolean = false

    Returns Entity<Exclude<any, TComponent>>

publicremoveGraphic

  • removeGraphic(graphic: Graphic): void
  • Remove an instance of a [[Graphic]] from this tile


    Parameters

    Returns void

publicremoveTag

  • removeTag(tag: string): void
  • Removes a tag on the entity

    Removals are deferred until the end of update


    Parameters

    • tag: string

    Returns void

publicunparent

  • unparent(): void
  • Unparents this entity, if there is a parent. Otherwise it does nothing.


    Returns void