Foundation.Tile
The most basic form of drawable object, Tiles are axis-aligned rectangle objects which are filled with a texture region. Tiles cannot be assigned colliders (though they can be checked for bonds-to-bounds overlaps with other drawable types). Tiles are not transformable, but their bounding rectangle can be freely modified for cheap movement, scaling etc. Tiles are ideal for non-interactive scenery, or for simple axis-aligned objects.
Tiles which are moved, scaled etc. retain no memory of their original geometry.
For a more complex drawable object, see the Sprite type.
Example
// Create a tile at 100, 200 which is 300 units wide by 400 units high
var tile = new Foundation.Tile(
new Foundation.Rectangle(100, 200, 300, 400),
someTexture.getRegion('all')
);
...
// Add the tile to a layer (path from default game prefab)
someGame['layers']['default'].pushBack(tile);
...
// Move by direct bounds modification:
tile.bounds.x += 10;
...
// Move tile to another layer
someGame['layers']['another'].pushBack(tile);
// Remove tile from its current layer
tile.layer.remove(tile);
Implementation Details
Reference paths
'/foundation/_digest.ts''/foundation/core/actors/_digest.ts''/foundation/core/actors/Tile.ts'
Extends
This type extends:
Equality check is deep. Clone is deep.
Implements
This type implements the following interfaces:
Constructors
(bounds: Rectangle, image: TextureRegion = null, alpha: number = 1)
- Define tile position as a rectangle. Image and alpha values are optional.
Properties
alpha: number
- The tile's drawing alpha value in the range 0 (fully transparent) to 1 (fully opaque).
- When setting, value will be clamped to 0, 1.
bounds: Rectangle
- Reference to the tile's bounding rectangle. This is a reference to the raw bounding rectangle, changes to component values will be preserved.
image: TextureRegion
- Reference to the tile's fill object (a TextureRegion instance).
- May be
null.
Instance Methods
clearImage(): TextureRegion
- Removes and nulls the tile's current image.
- Returns the removed image.
getOriginalBounds(): Rectangle
- Tiles are not transformable. As such, this method acts as a simple alias for the
boundsproperty.
overlaps(other: {bounds: Rectangle}): boolean
- Returns true if the tile's bounds overlap the passed rectangle.
handleOverlap(other: Tile|Sprite): void
- Base implementation is empty, override to add behavior.
- If using the
CollisionUtilitymethods to check for overlapping items, this method will be called for each detected overlap. - Overlapping tile or sprite will be passed on call.
- Overlaps are based on axis-aligned bounding box checks and are not the same as collisions (which occur on colliders). Tiles cannot have colliders, therefore are not collidable.