TileMap

The backbone.

Home

Classes

• TileMap
• ShapeGen
• TerrainGenerator

Extra

• Tutorials
• Demo

Description

The TileMap is essentially a 2D array of Renderables. You can place the TileMap at any world coordinate, and its length and width can be any arbitrary number of tiles. The side length of tiles within the map can also be adjusted to make the entire structure bigger or smaller.

Once the TileMap is created, we attempt to use tile coordinates as much as possible to avoid confusion. Tile coordinates must be integers between 0 and the tileMap's width or height minus one.

When creating a tile you must pass in a renderable that has been initialized with new. We chose this framework so that any texture could be used, from simple colors to animated sprites. Unfortunately this required a large number of calls to 'new' which isn't ideal for real-time terrain generation. We did a great deal of optimization in the the draw() function so that only the visible tiles are drawn.

The tileMap provides support for collision detection with getBounds, which returns the bounding box for a given tile. We don't recommend checking the collision for every tile in the map. TerrainGenerator provides a function for optimized collision checking which only returns the collision bounds of the surface tiles.

Constructor

new TileMap (xPos, yPos, tileWidth, width, height)

Constructor that creates a TileMap

xPos | float | The world coordinate x position of the TileMap
yPos | float | The world coordinate y position of the TileMap
tileWidth | float | The world coordinate width of each tile
width | int | The width of the TileMap in tiles
height | int | The height of the TileMap in tiles

Methods

getWCHeight ()

Returns the world coordinate height of the TileMap


getWCWidth ()

Returns the world coordinate width of the TileMap


getWidth ()

Returns the width of the TileMap in tiles


getHeight ()

Returns the height of the TileMap in tiles


getXPos ()

Returns the world coordinate x position of the TileMap


getYPos ()

Returns the world coordinate y position of the TileMap


clearMap ()

Removes all tiles from the TileMap


addTile (tileX, tileY, renderable)

Adds a renderable to the TileMap

tileX | int | The target x for the new tile
tileY | int | The target y for the new tile
renderable | Renderable | The renderable to be put in the TileMap


removeTile (tileX, tileY)

Removes a tile from the TileMap

tileX | int | The target x to remove from
tileY | int | The target y to remove from


draw (camera)

Draws the TileMap

camera | Camera | The camera to draw the TileMap on


isTileAt (xPos, yPos)

Returns true if tile is at given x and y

tileX | int | The target x to check for a tile
tileY | int | The target y to check for a tile


getBounds (xPos, yPos)

Returns a bounding box for the tile at given x and y

tileX | int | The target x to get bounding box
tileY | int | The target y to get bounding box