API Docs for: 1.4.0
Show:

Kiwi.GameObjects.Tilemap.TileMapLayer Class

Extends Kiwi.Entity
Module: Tilemap
Parent Module: GameObjects

Available since 1.3.0

GameObject containing the core functionality for every type of tilemap layer that can be generated. This class should not be directly used. Classes extending this should be used instead.

Constructor

Kiwi.GameObjects.Tilemap.TileMapLayer

(
  • tilemap
  • name
  • atlas
  • data
  • tw
  • th
  • [x=0]
  • [y=0]
  • [w=0]
  • [h=0]
)
TileMapLayer

Defined in src\gameobjects\tilemap\TileMapLayer.ts:11

Available since 1.3.0

Parameters:

  • tilemap Kiwi.GameObjects.Tilemap.TileMap

    The TileMap that this layer belongs to.

  • name String

    The name of this TileMapLayer.

  • atlas Kiwi.Textures.TextureAtlas

    The texture atlas that should be used when rendering this TileMapLayer onscreen.

  • data Number

    The information about the tiles.

  • tw Number

    The width of a single tile in pixels. Usually the same as the TileMap unless told otherwise.

  • th Number

    The height of a single tile in pixels. Usually the same as the TileMap unless told otherwise.

  • [x=0] Number optional

    The x coordinate of the tilemap in pixels.

  • [y=0] Number optional

    The y coordinate of the tilemap in pixels.

  • [w=0] Number optional

    The width of the whole tilemap in tiles. Usually the same as the TileMap unless told otherwise.

  • [h=0] Number optional

    The height of the whole tilemap in tiles. Usually the same as the TileMap unless told otherwise.

Returns:

TileMapLayer:

Methods

_calculateBoundaries

(
  • camera
  • matrix
)
protected

Used to calculate the position of the tilemap on the stage as well as how many tiles can fit on the screen. All coordinates calculated are stored as temporary properties (maxX/Y, startX/Y).

Parameters:

  • camera Camera
  • matrix Matrix

addTag

(
  • tag
)
public

Inherited from Kiwi.Entity: src\core\Entity.ts:464

Available since 1.1.0

Adds a new Tag to this Entity. Useful for identifying large amounts of the same type of GameObjects. You can pass multiple strings to add multiple tags.

Parameters:

  • tag String

    The tag that you would like to add to this Entity.

centerAnchorPoint

() public

Centers the anchor point to the middle of the width/height of the tilemap.

chartToScreen

(
  • chartPt
  • [tileW]
  • [tileH]
)
Object deprecated public

Defined in src\gameobjects\tilemap\TileMapLayer.ts:732

Available since 1.3.0

Deprecated on the TileMapLayer class since it is for 'Isometric' maps only.

Parameters:

  • chartPt Any

    A Object containing x/y properties of the tile.

  • [tileW] Number optional

    The width of the tile

  • [tileH] Number optional

    The height of the tile

Returns:

Object:

With x/y properties of the location of the map onscreen.

countTiles

(
  • [type]
)
Number public

Returns the total number of tiles. Either for a particular type if passed, otherwise of any type if not passed.

Parameters:

  • [type] Number optional

    The type of tile you want to count.

Returns:

Number:

The number of tiles on this layer.

destroy

(
  • [immediate=false]
)
public

Used to completely destroy this entity and of its components. Used for garbage collection and developers can also use it as needed. It is more reliable to use "exists = false", as this will ensure that "destroy" is called at a convenient time.

Parameters:

  • [immediate=false] Boolean optional

    If the object should be immediately removed or if it should be removed at the end of the next update loop.

fill

(
  • type
  • [x=0]
  • [y=0]
  • [width=this.width]
  • [height=this.height]
)
public

Makes all of the tiles in the area specified a single type that is passed.

Parameters:

  • type Number

    The type of tile you want to fill in the area with.

  • [x=0] Number optional

    The starting tile on the x axis to fill.

  • [y=0] Number optional

    The starting tile on the y axis to fill.

  • [width=this.width] Number optional

    How far across you want to go.

  • [height=this.height] Number optional

    How far down you want to go.

getCollidableTiles

(
  • [x=0]
  • [y=0]
  • [width=widthOfMap]
  • [height=heightOfmap]
  • [collisionType=ANY]
)
Object public

Returns the tiles which can collide with other objects (on ANY side unless otherwise specified) within an area provided. By default the area is the whole tilemap.

Parameters:

  • [x=0] Number optional

    The x coordinate of the first tile to check.

  • [y=0] Number optional

    The y coordinate of the first tile to check.

  • [width=widthOfMap] Number optional

    The width from the x coordinate.

  • [height=heightOfmap] Number optional

    The height from the y coordinate.

  • [collisionType=ANY] Number optional

    The type of collidable tiles that should be return. By default ANY type of collidable tiles will be returned.

Returns:

Object:

Returns an Array of Objects containing information about the tiles which were found. Index/X/Y information is contained within each Object.

getIndexFromCoords

(
  • x
  • y
)
Number public

Returns the index of the tile based on the x and y pixel coordinates that are passed. If no tile is a the coordinates given then -1 is returned instead. Coordinates are in pixels not tiles and use the world coordinates of the tilemap.

Functionality needs to be added by classes extending this class.

Parameters:

  • x Number

    The x coordinate of the Tile you would like to retrieve.

  • y Number

    The y coordinate of the Tile you would like to retrieve.

Returns:

Number:

Either the index of the tile retrieved or -1 if none was found.

getIndexFromXY

(
  • x
  • y
)
Number public

Returns the index of the tile based on the x and y coordinates of the tile passed. If no tile is a the coordinates given then -1 is returned instead. Coordinates are in tiles not pixels.

Parameters:

  • x Number

    The x coordinate of the Tile you would like to retrieve.

  • y Number

    The y coordinate of the Tile you would like to retrieve.

Returns:

Number:

Either the index of the tile retrieved or -1 if none was found.

getIndexsByType

(
  • type
)
Number public

Returns the indexes of every tile of a type you pass.

Parameters:

  • type Number

Returns:

Number:

getOverlappingTiles

(
  • entity
  • [collisionType=ANY]
)
Object public

Returns the tiles which overlap with a provided entities hitbox component. Only collidable tiles on ANY side will be returned unless you pass a particular side. Note: Classes extending this class need to

Parameters:

  • entity Kiwi.Entity

    The entity you would like to check for the overlap.

  • [collisionType=ANY] Number optional

    The particular type of collidable tiles which you would like to check for.

Returns:

Object:

Returns an Array of Objects containing information about the tiles which were found. Index/X/Y information is contained within each Object.

getTileFromCoords

(
  • x
  • y
)
Kiwi.GameObjects.Tilemap.TileType public

Returns the TileType for a tile that is at a particular coordinate passed. If no tile is found then null is returned instead. Coordinates passed are in pixels and use the world coordinates of the tilemap.

Parameters:

  • x Number
  • y Number

getTileFromIndex

(
  • index
)
Kiwi.GameObjects.Tilemap.TileType public

Returns the TileType of a tile by an index passed. Thanks to @rydairegames

Parameters:

  • index Number

getTileFromXY

(
  • x
  • y
)
Kiwi.GameObjects.Tilemap.TileType public

Returns the TileType for a tile that is at a particular set of coordinates passed. If no tile is found the null is returned instead. Coordinates passed are in tiles.

Parameters:

  • x Number
  • y Number

hasTag

(
  • tag
)
Boolean public

Inherited from Kiwi.Entity: src\core\Entity.ts:499

Available since 1.1.0

Checks to see if this Entity has a Tag based upon a string which you pass.

Parameters:

  • tag String

Returns:

Boolean:

objType

() String public

The type of object that it is.

Returns:

String:

"TileMapLayer"

randomizeTiles

(
  • [types]
  • [x=0]
  • [y=0]
  • [width=this.width]
  • [height=this.height]
)
public

Randomizes the types of tiles used in an area of the layer. You can choose which types of tiles to use, and the area. Default tile types used are everyone avaiable.

Parameters:

  • [types] Number optional

    A list of TileTypes that can be used. Default is every tiletype on the TileMap.

  • [x=0] Number optional

    The starting tile on the x axis to fill.

  • [y=0] Number optional

    The starting tile on the y axis to fill.

  • [width=this.width] Number optional

    How far across you want to go.

  • [height=this.height] Number optional

    How far down you want to go.

removeTag

(
  • tag
)
public

Inherited from Kiwi.Entity: src\core\Entity.ts:483

Available since 1.1.0

Removes a Tag from this Entity.

Parameters:

  • tag String

    The tag that you would like to remove from this Entity.

render

(
  • camera
)
public

The render loop which is used when using the Canvas renderer.

Parameters:

  • camera Camera

renderGL

(
  • camera
  • gl
  • [params=null]
)
public

Renders the entity using the canvas renderer. This isn't called until the Entity has been added to a Group/State which is active. This functionality is handled by the sub classes.

Parameters:

  • camera Kiwi.Camera
  • gl WebGLRenderingContext
  • [params=null] Object optional

    params

replaceTiles

(
  • typeA
  • typeB
  • [x=0]
  • [y=0]
  • [width=this.width]
  • [height=this.height]
)
public

Replaces all tiles of typeA to typeB in the area specified. If no area is specified then it is on the whole layer.

Parameters:

  • typeA Number

    The type of tile you want to be replaced.

  • typeB Number

    The type of tile you want to be used instead.

  • [x=0] Number optional

    The starting tile on the x axis to fill.

  • [y=0] Number optional

    The starting tile on the y axis to fill.

  • [width=this.width] Number optional

    How far across you want to go.

  • [height=this.height] Number optional

    How far down you want to go.

scaleToHeight

(
  • value
)
public

Scales the tilemaps to the value passed.

Parameters:

  • value Number

scaleToWidth

(
  • value
)
public

Scales the tilemap to the value passed.

Parameters:

  • value Number

screenToChart

(
  • scrPt
  • [tileW]
  • [tileH]
)
Object deprecated public

Defined in src\gameobjects\tilemap\TileMapLayer.ts:751

Available since 1.3.0

Deprecated on the TileMapLayer class since it is for 'Isometric' maps only.

Parameters:

  • scrPt Any

    An object containing x/y coordinates of the point on the screen you want to convert to tile coordinates.

  • [tileW] Number optional

    The width of a single tile.

  • [tileH] Number optional

    The height of a single tile.

Returns:

Object:

With x/y properties of the location of tile on the screen.

setTile

(
  • x
  • y
  • tileType
)
Boolean public

Sets the tile to be used at the coordinates provided. Can be used to override a tile that may already exist at the location.

Parameters:

  • x Number

    The coordinate of the tile on the x axis.

  • y Number

    The coordinate of the tile on the y axis.

  • tileType Number

    The type of tile that should be now used.

Returns:

Boolean:

If a tile was changed or not.

setTileByIndex

(
  • index
  • tileType
)
public

Sets the tile to be used at the index provided. Can be used to override a tile that may already exist at the location.

Parameters:

  • index Number

    The index of the tile that you want to change.

  • tileType Number

    The new tile type to be used at that position.

swapTiles

(
  • typeA
  • typeB
  • [x=0]
  • [y=0]
  • [width=this.width]
  • [height=this.height]
)
public

Swaps all the tiles that are typeA -> typeB and typeB -> typeA inside the area specified. If no area is specified then it is on the whole layer.

Parameters:

  • typeA Number

    The type of tile you want to be replaced with typeB.

  • typeB Number

    The type of tile you want to be replaced with typeA.

  • [x=0] Number optional

    The starting tile on the x axis to fill.

  • [y=0] Number optional

    The starting tile on the y axis to fill.

  • [width=this.width] Number optional

    How far across you want to go.

  • [height=this.height] Number optional

    How far down you want to go.

update

() public

The update loop that is executed when this TileMapLayer is add to the Stage.

Properties

_active

Boolean private

An active Entity is one that has its update method called by its parent.

Default: true

_alpha

Number private

The alpha of this entity.

_cellIndex

Number private

Holds the current cell that is being used by the entity.

Default: 0

_clock

Kiwi.Clock private

The clock that this entity use's for time based calculations. This generated by the state on instatiation.

_data

Array protected

A list containing all the types of tiles found on this TileMapLayer.

_dirty

Boolean private

A value used by components to control if the Entity needs re-rendering

_exists

Boolean private

If an Entity no longer exists it is cleared for garbage collection or pool re-allocation

_inputEnabled

Boolean deprecated private

Inherited from Kiwi.Entity: src\core\Entity.ts:568

Deprecated: As of 1.2.3, nothing was found to use this.

Controls if this Entity is input enabled or not (i.e. responds to touch/mouse events)

_maxX

Number protected

Used whilst rendering to calculate the number of tiles to be rendered on the X axis. Is updated each frame, via the _calculateBoundaries method.

_maxY

Number protected

Used whilst rendering to calculate the number of tiles to be rendered on the Y axis. Is updated each frame, via the _calculateBoundaries method.

_parent

Kiwi.Group private

The group that this entity belongs to. If added onto the state then this is the state.

_startX

Number protected

Used whilst rendering to calculate which is the first tile to be rendered on the X axis. Is updated each frame, via the _calculateBoundaries method.

_startY

Number protected

Used whilst rendering to calculate which is the first tile to be rendered on the Y axis. Is updated each frame, via the _calculateBoundaries method.

_tags

Array private

Inherited from Kiwi.Entity: src\core\Entity.ts:454

Available since 1.1.0

Any tags that are on this Entity. This can be used to grab GameObjects or Groups on the whole game which have these particular tags. By default Entitys contain no tags.

_temptype

TileType protected

Temporary property that holds the tileType of the current tile being rendered.

_visible

Boolean private

A boolean that indicates whether or not this entity is visible or not. Note that is does not get set to false if the alpha is 0.

Default: true

_willRender

Boolean deprecated private

Inherited from Kiwi.Entity: src\core\Entity.ts:543

Deprecated: Use _visible instead

Controls whether render is automatically called by the parent.

Default: true

active

Boolean public

Toggles the active state of this Entity. An Entity that is active has its update method called by its parent. This method should be over-ridden to handle specific dom/canvas/webgl implementations.

alpha

Number public

Alpha of this entity. A number between 0 (invisible) and 1 (completely visible).

anchorPointX

Number public

Inherited from Kiwi.Entity: src\core\Entity.ts:203

Available since 1.1.0

The anchor point on the x-axis. This is just aliased to the rotPointX on the transform object.

anchorPointY

Number public

Inherited from Kiwi.Entity: src\core\Entity.ts:217

Available since 1.1.0

The anchor point on the y-axis. This is just aliased to the rotPointY on the transform object.

atlas

Kiwi.Textures.TextureAtlas public

The texture atlas that should be used when rendering.

cellIndex

Number deprecated public

Inherited from Kiwi.Entity but overwritten in src\gameobjects\tilemap\TileMapLayer.ts:169

Deprecated: Not functional on this object.

Available since 1.1.0

Override function to prevent unwanted inherited behaviour. Do not call. Because TileMapLayer extends Entity, it has a cellIndex parameter. However, it does not use a single atlas index, so this parameter is meaningless. It has deliberately been set to do nothing.

clock

Kiwi.Time.Clock public

The Clock used to update this all of this Entities components (defaults to the Game MasterClock)

components

Kiwi.ComponentManager public

The Component Manager

corner1

Kiwi.Geom.Point protected

Defined in src\gameobjects\tilemap\TileMapLayer.ts:664

Available since 1.1.0

Corner values used internally.

corner2

Kiwi.Geom.Point protected

Defined in src\gameobjects\tilemap\TileMapLayer.ts:672

Available since 1.1.0

Corner values used internally.

corner3

Kiwi.Geom.Point protected

Defined in src\gameobjects\tilemap\TileMapLayer.ts:681

Available since 1.1.0

Corner values used internally.

corner4

Kiwi.Geom.Point protected

Defined in src\gameobjects\tilemap\TileMapLayer.ts:690

Available since 1.1.0

Corner values used internally.

data

Array public

Defined in src\gameobjects\tilemap\TileMapLayer.ts:223

Available since 1.3.0

READ ONLY: Returns the raw data for this tilemap.

dirty

Boolean public

A value used by components to control if the Entity needs re-rendering

exists

Boolean public

Toggles the existence of this Entity. An Entity that no longer exists can be garbage collected or re-allocated in a pool.

game

Game public

The game this Entity belongs to

height

Number public

The height of this TileMap in tiles.

heightInPixels

Number public

The height of the layer in pixels. This property is READ ONLY.

id

String public

A unique identifier for this Entity within the game used internally by the framework. See the name property for a friendly version.

inputEnabled

Boolean deprecated public

Inherited from Kiwi.Entity: src\core\Entity.ts:577

Deprecated: As of 1.2.3, nothing was found to use this.

Controls if this Entity is input enabled or not (i.e. responds to touch/mouse events) This method should be over-ridden to handle specific game object implementations.

name

String public

A name for this Entity. This is not checked for uniqueness within the Game, but is very useful for debugging

Default: ''

orientation

String public

The orientation of the of tilemap. TileMaps can be either 'orthogonal' (normal) or 'isometric'.

parent

Group public

The group that this entity belongs to/is a child of once added to one. If added onto the state then this is the state.

Sub-properties:

physics

ArcadePhysics public

The physics component contained on the Tilemap. Use for basic collisions between People and Tiles. Note: That tilemap layers a immovable and collisions with tiles are set on the individual TileTypes that are contained on the TileMap.

properties

Object public

Properties about that this TileMapLayer has when it was created from a JSON file.

rotation

Number public

Rotation of this Entity. This is just aliased to the transform property.

rotPointX

Number public

The rotation point on the x-axis. This is just aliased to the rotPointX on the transform object.

rotPointY

Number public

The rotation point on the y-axis. This is just aliased to the rotPointY on the transform object.

scale

Number public

Inherited from Kiwi.Entity: src\core\Entity.ts:153

Available since 1.1.0

Scale both axes of this Entity. This is just aliased to the transform property. This is WRITE-ONLY.

scaleX

Number public

Scale X of this Entity. This is just aliased to the transform property.

scaleY

Number public

Scale Y coordinate of this Entity. This is just aliased to the transform property.

state

State public

The state this Entity belongs to (either the current game state or a persistent world state)

tileData

Array public

READ ONLY: A list containing all of the types of tiles found on this TileMapLayer. Same as the data property.

tileHeight

Number public

The height of a single tile.

tilemap

TileMap public

The tilemap that this TileMapLayer is a part of.

tileWidth

Number public

The width of a single tile.

transform

Kiwi.Geom.Transform public

Represents the position, scale, rotation and registration of this Entity.

visible

Boolean public

Set the visibility of this entity. True or False.

Default: true

width

Number public

The width of this TileMap in tiles.

widthInPixels

Number public

The width of the layer in pixels. This property is READ ONLY.

willRender

Boolean deprecated public

Inherited from Kiwi.Entity: src\core\Entity.ts:553

Deprecated: Use visible instead

Toggles if this Entity will be rendered.

Default: true

worldX

Number public

Inherited from Kiwi.Entity: src\core\Entity.ts:104

Available since 1.1.0

X coordinate of this Entity in world space; that is, after inheriting parent transforms. This is just aliased to the transform property. Property is READ-ONLY.

worldY

Number public

Inherited from Kiwi.Entity: src\core\Entity.ts:115

Available since 1.1.0

Y coordinate of this Entity in world space; that is, after inheriting parent transforms. This is just aliased to the transform property. Property is READ-ONLY.

x

Number public

X coordinate of this Entity. This is just aliased to the transform property.

y

Number public

Y coordinate of this Entity. This is just aliased to the transform property.