Kiwi.GameObjects.Tilemap.TileMapLayer Class
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]
Parameters:
-
tilemap
Kiwi.GameObjects.Tilemap.TileMapThe TileMap that this layer belongs to.
-
name
StringThe name of this TileMapLayer.
-
atlas
Kiwi.Textures.TextureAtlasThe texture atlas that should be used when rendering this TileMapLayer onscreen.
-
data
NumberThe information about the tiles.
-
tw
NumberThe width of a single tile in pixels. Usually the same as the TileMap unless told otherwise.
-
th
NumberThe height of a single tile in pixels. Usually the same as the TileMap unless told otherwise.
-
[x=0]
Number optionalThe x coordinate of the tilemap in pixels.
-
[y=0]
Number optionalThe y coordinate of the tilemap in pixels.
-
[w=0]
Number optionalThe width of the whole tilemap in tiles. Usually the same as the TileMap unless told otherwise.
-
[h=0]
Number optionalThe height of the whole tilemap in tiles. Usually the same as the TileMap unless told otherwise.
Returns:
Item Index
Methods
- _calculateBoundaries
- addTag
- centerAnchorPoint
- chartToScreen deprecated
- countTiles
- destroy
- fill
- getCollidableTiles
- getIndexFromCoords
- getIndexFromXY
- getIndexsByType
- getOverlappingTiles
- getTileFromCoords
- getTileFromIndex
- getTileFromXY
- hasTag
- objType
- randomizeTiles
- removeTag
- render
- renderGL
- replaceTiles
- scaleToHeight
- scaleToWidth
- screenToChart deprecated
- setTile
- setTileByIndex
- swapTiles
- update
Properties
- _active
- _alpha
- _cellIndex
- _clock
- _data
- _dirty
- _exists
- _inputEnabled deprecated
- _maxX
- _maxY
- _parent
- _startX
- _startY
- _tags
- _temptype
- _visible
- _willRender deprecated
- active
- alpha
- anchorPointX
- anchorPointY
- atlas
- cellIndex deprecated
- clock
- components
- corner1
- corner2
- corner3
- corner4
- data
- dirty
- exists
- game
- height
- heightInPixels
- id
- inputEnabled deprecated
- name
- orientation
- parent
- physics
- properties
- rotation
- rotPointX
- rotPointY
- scale
- scaleX
- scaleY
- state
- tileData
- tileHeight
- tilemap
- tileWidth
- transform
- visible
- width
- widthInPixels
- willRender deprecated
- worldX
- worldY
- x
- y
Methods
_calculateBoundaries
-
camera
-
matrix
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
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
StringThe 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]
Deprecated on the TileMapLayer class since it is for 'Isometric' maps only.
Parameters:
-
chartPt
AnyA Object containing x/y properties of the tile.
-
[tileW]
Number optionalThe width of the tile
-
[tileH]
Number optionalThe height of the tile
Returns:
With x/y properties of the location of the map onscreen.
countTiles
-
[type]
Returns the total number of tiles. Either for a particular type if passed, otherwise of any type if not passed.
Parameters:
-
[type]
Number optionalThe type of tile you want to count.
Returns:
The number of tiles on this layer.
destroy
-
[immediate=false]
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 optionalIf 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]
Makes all of the tiles in the area specified a single type that is passed.
Parameters:
-
type
NumberThe type of tile you want to fill in the area with.
-
[x=0]
Number optionalThe starting tile on the x axis to fill.
-
[y=0]
Number optionalThe starting tile on the y axis to fill.
-
[width=this.width]
Number optionalHow far across you want to go.
-
[height=this.height]
Number optionalHow far down you want to go.
getCollidableTiles
-
[x=0]
-
[y=0]
-
[width=widthOfMap]
-
[height=heightOfmap]
-
[collisionType=ANY]
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 optionalThe x coordinate of the first tile to check.
-
[y=0]
Number optionalThe y coordinate of the first tile to check.
-
[width=widthOfMap]
Number optionalThe width from the x coordinate.
-
[height=heightOfmap]
Number optionalThe height from the y coordinate.
-
[collisionType=ANY]
Number optionalThe type of collidable tiles that should be return. By default ANY type of collidable tiles will be returned.
Returns:
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
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
NumberThe x coordinate of the Tile you would like to retrieve.
-
y
NumberThe y coordinate of the Tile you would like to retrieve.
Returns:
Either the index of the tile retrieved or -1 if none was found.
getIndexFromXY
-
x
-
y
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
NumberThe x coordinate of the Tile you would like to retrieve.
-
y
NumberThe y coordinate of the Tile you would like to retrieve.
Returns:
Either the index of the tile retrieved or -1 if none was found.
getIndexsByType
-
type
Returns the indexes of every tile of a type you pass.
Parameters:
-
type
Number
Returns:
getOverlappingTiles
-
entity
-
[collisionType=ANY]
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.EntityThe entity you would like to check for the overlap.
-
[collisionType=ANY]
Number optionalThe particular type of collidable tiles which you would like to check for.
Returns:
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
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
Returns:
getTileFromIndex
-
index
Returns the TileType of a tile by an index passed. Thanks to @rydairegames
Parameters:
-
index
Number
Returns:
getTileFromXY
-
x
-
y
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
Returns:
hasTag
-
tag
Checks to see if this Entity has a Tag based upon a string which you pass.
Parameters:
-
tag
String
Returns:
objType
()
String
public
The type of object that it is.
Returns:
"TileMapLayer"
randomizeTiles
-
[types]
-
[x=0]
-
[y=0]
-
[width=this.width]
-
[height=this.height]
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 optionalA list of TileTypes that can be used. Default is every tiletype on the TileMap.
-
[x=0]
Number optionalThe starting tile on the x axis to fill.
-
[y=0]
Number optionalThe starting tile on the y axis to fill.
-
[width=this.width]
Number optionalHow far across you want to go.
-
[height=this.height]
Number optionalHow far down you want to go.
removeTag
-
tag
Removes a Tag from this Entity.
Parameters:
-
tag
StringThe tag that you would like to remove from this Entity.
render
-
camera
The render loop which is used when using the Canvas renderer.
Parameters:
-
camera
Camera
renderGL
-
camera
-
gl
-
[params=null]
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 optionalparams
replaceTiles
-
typeA
-
typeB
-
[x=0]
-
[y=0]
-
[width=this.width]
-
[height=this.height]
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
NumberThe type of tile you want to be replaced.
-
typeB
NumberThe type of tile you want to be used instead.
-
[x=0]
Number optionalThe starting tile on the x axis to fill.
-
[y=0]
Number optionalThe starting tile on the y axis to fill.
-
[width=this.width]
Number optionalHow far across you want to go.
-
[height=this.height]
Number optionalHow far down you want to go.
scaleToHeight
-
value
Scales the tilemaps to the value passed.
Parameters:
-
value
Number
scaleToWidth
-
value
Scales the tilemap to the value passed.
Parameters:
-
value
Number
screenToChart
-
scrPt
-
[tileW]
-
[tileH]
Deprecated on the TileMapLayer class since it is for 'Isometric' maps only.
Parameters:
-
scrPt
AnyAn object containing x/y coordinates of the point on the screen you want to convert to tile coordinates.
-
[tileW]
Number optionalThe width of a single tile.
-
[tileH]
Number optionalThe height of a single tile.
Returns:
With x/y properties of the location of tile on the screen.
setTile
-
x
-
y
-
tileType
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
NumberThe coordinate of the tile on the x axis.
-
y
NumberThe coordinate of the tile on the y axis.
-
tileType
NumberThe type of tile that should be now used.
Returns:
If a tile was changed or not.
setTileByIndex
-
index
-
tileType
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
NumberThe index of the tile that you want to change.
-
tileType
NumberThe new tile type to be used at that position.
swapTiles
-
typeA
-
typeB
-
[x=0]
-
[y=0]
-
[width=this.width]
-
[height=this.height]
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
NumberThe type of tile you want to be replaced with typeB.
-
typeB
NumberThe type of tile you want to be replaced with typeA.
-
[x=0]
Number optionalThe starting tile on the x axis to fill.
-
[y=0]
Number optionalThe starting tile on the y axis to fill.
-
[width=this.width]
Number optionalHow far across you want to go.
-
[height=this.height]
Number optionalHow 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
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.
_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
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
The anchor point on the x-axis. This is just aliased to the rotPointX on the transform object.
anchorPointY
Number
public
The anchor point on the y-axis. This is just aliased to the rotPointY on the transform object.
cellIndex
Number
deprecated
public
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)
data
Array
public
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
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:
-
val
Kiwi.Group
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
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
Toggles if this Entity will be rendered.
Default: true
worldX
Number
public
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
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.