Class R.resources.types.TileMap
Extends
R.engine.GameObject.
A 2d tile map, comprised of many tiles. Tiles in a map are all the same
size.
Defined in: tilemap.js.
Constructor Attributes | Constructor Name and Description |
---|---|
A tile map is a collection of tiles, all the same dimensions.
|
Field Attributes | Field Name and Description |
---|---|
The maximum length of a cast ray (1000)
|
- Fields borrowed from class R.struct.Container:
- EMPTY
Method Attributes | Method Name and Description |
---|---|
castRay(tileMap, rayInfo)
Cast a ray through the tile map, looking for collisions along the
ray.
|
|
clearTile(x, y)
Clear the tile at the given position, returning the tile that occupied the
position, or
null if there was no tile. |
|
computeSolidityMap(tile)
Compute the solidity map for a tile, based on the alpha value of each pixel in the
tile image.
|
|
deserialize(obj, clazz, clazz)
Deserialize the object back into a tile map.
|
|
destroy()
Destroy the tilemap instance
|
|
Get the basis tile for the tile map.
|
|
Gets the class name of this object.
|
|
Returns the parallax distance of the tile map along each axis.
|
|
When editing objects, this method returns an object which
contains the properties with their getter and setter methods.
|
|
getTile(x, y)
Get the tile at the given position.
|
|
getTileAtPoint(point)
Get the tile at the given point.
|
|
Get the z-index of the tile map.
|
|
release()
Release the tilemap back into the pool for reuse
|
|
serialize(tilemap, defaults)
Serialize the tile map into an object.
|
|
setDimensions(x, y)
Set the dimensions of the tile map.
|
|
setParallax(xOrPt, y)
Set the parallax distance of the tile map from the viewer's eye.
|
|
setTile(tile, x, y)
Set the tile at the given position.
|
|
setZIndex(zIndex)
Set the z-index of the tile map.
|
|
update(renderContext, time, dt)
Update the tile map, rendering it to the context.
|
- Methods borrowed from class R.engine.GameObject:
- add, componentSort, getComponent, getComponentByClass, getRenderContext, isDirty, isKeepAlive, markDirty, remove, setKeepAlive, setRenderContext, wasDirty
- Methods borrowed from class R.struct.HashContainer:
- cleanUp, clear, get, isInHash, removeAtIndex, removeHash
- Methods borrowed from class R.struct.Container:
- addAll, append, clone, concat, contains, filter, forEach, fromArray, getAll, getObjects, insert, iterator, reduce, replace, replaceAt, size, sort, subset, toXML
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, getId, getName, getObjectDataModel, isDestroyed, setName, setObjectDataModel, toString
Class Detail
R.resources.types.TileMap(name)
A tile map is a collection of tiles, all the same dimensions.
- Parameters:
- name
- {String} The name of the tilemap
Field Detail
MAX_RAY_LENGTH
The maximum length of a cast ray (1000)
Method Detail
{R.struct.rayInfo}
castRay(tileMap, rayInfo)
Cast a ray through the tile map, looking for collisions along the
ray. If a collision is found, a R.struct.CollisionData object
will be returned or
null
if otherwise.
If a collision occurs, the value stored in R.struct.CollisionData#shape1
is the tile which was collided with. The value in R.struct.CollisionData#impulseVector
is a vector to separate the game object from the tile.
- Parameters:
- tileMap
- {R.resources.types.TileMap} The tile map to test against
- rayInfo
- {R.start.rayInfo} The ray info structure that defines the ray to test
- Returns:
- {R.struct.rayInfo} The ray info structure passed into the cast method. If a collision occurred, the shape and impact point will be set.
{R.resources.types.Tile}
clearTile(x, y)
Clear the tile at the given position, returning the tile that occupied the
position, or
null
if there was no tile.
- Parameters:
- x
- {Number} The X position
- y
- {Number} The Y position
- Returns:
- {R.resources.types.Tile}
computeSolidityMap(tile)
Compute the solidity map for a tile, based on the alpha value of each pixel in the
tile image. The resource defines what the alpha threshold is.
- Parameters:
- tile
- {R.resources.types.tile} The tile to compute the map for
deserialize(obj, clazz, clazz)
Deserialize the object back into a tile map.
- Parameters:
- obj
- {Object} The object to deserialize
- clazz Optional
- {Class} The object class to populate
- clazz
destroy()
Destroy the tilemap instance
{R.resources.types.Tile}
getBaseTile()
Get the basis tile for the tile map. The first tile within a tile map determines
the basis of all tiles. Thus, if you drop a 32x32 tile into the tile map, all tiles
must be divisible by 32 along each axis.
- Returns:
- {R.resources.types.Tile}
{String}
getClassName()
Gets the class name of this object.
- Returns:
- {String} The string "R.resources.types.TileMap"
{R.math.Vector2D}
getParallax()
Returns the parallax distance of the tile map along each axis.
- Returns:
- {R.math.Vector2D}
{Object}
getProperties()
When editing objects, this method returns an object which
contains the properties with their getter and setter methods.
- Returns:
- {Object} The properties object
{R.resources.types.Tile}
getTile(x, y)
Get the tile at the given position. The position is a tile location between
zero and the dimensions of the tile map along the X and Y axis. For a tile map
that is 200 x 200, X and Y would be between 0 and 200.
- Parameters:
- x
- {Number} The X position
- y
- {Number} The Y position
- Returns:
- {R.resources.types.Tile}
{R.resources.types.Tile}
getTileAtPoint(point)
Get the tile at the given point. The point is a world location which will be
transformed into a tile location. The point will be adjusted to reflect the
position within the tile.
- Parameters:
- point
- {R.math.Point2D} The point to retrieve the tile for
- Returns:
- {R.resources.types.Tile} The tile, or
null
{Number}
getZIndex()
Get the z-index of the tile map.
- Returns:
- {Number}
release()
Release the tilemap back into the pool for reuse
{Object}
serialize(tilemap, defaults)
Serialize the tile map into an object.
- Parameters:
- tilemap
- {R.resources.types.TileMap} The tile map to serialize
- defaults
- Returns:
- {Object}
setDimensions(x, y)
Set the dimensions of the tile map. Setting the dimensions will clear the tile map.
- Parameters:
- x
- {Number|R.math.Point2D}
- y
- {Number}
setParallax(xOrPt, y)
Set the parallax distance of the tile map from the viewer's eye. Setting the parallax distance
can create the illusion of depth when layers move at different rates along the X
and Y axis. The distance is a vector which specifies the amount of offset along each
axis, from the viewer's eye, with 1 being the middle plane. Each value should be a floating
point number with numbers closer to zero meaning closer to the eye (or faster change) and
numbers greater than 1 meaning farther from the eye (or slower change).
- Parameters:
- xOrPt
- {Number|R.math.Vector2D} The X offset, or a vector indicating the amount of offset
- y Optional
- {Number} The Y offset if
xOrPt
was a number
setTile(tile, x, y)
Set the tile at the given position.
- Parameters:
- tile
- {R.resources.types.Tile} The tile
- x
- {Number} The X position of the tile
- y
- {Number} The Y position of the tile
setZIndex(zIndex)
Set the z-index of the tile map.
- Parameters:
- zIndex
- {Number} The z-index (depth) of the tile map.
update(renderContext, time, dt)
Update the tile map, rendering it to the context.
- Parameters:
- renderContext
- {R.rendercontexts.AbstractRenderContext} The context the object exists within
- time
- {Number} The current engine time, in milliseconds
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.