Class: Tile

Core.Tile(texture, clip)

This class is an abstraction of an image. In Apate almost all images get drawn as tiles. Think of a Tile as a wrapper around images which also stores the part of the image should be visible. With this wrapper its possible to have multiple references with different parts of the same image. An image itself is represented by a Texture

Constructor

new Tile(texture, clip)

Constructs a Tile from with a given texture and an optional clip.
Parameters:
Name Type Description
texture Texture The image texture of the Tile
clip Core.Vec The visible area of the image
Example
// load a simple image as sprite
const player = Tile.fromImg(<img>);
// or load a sprite atlas / sheet with multiple sub images
const spriteAtlas = Tile.fromImg(<img>);
// in the first row of 8 pixel in the atlas is a walk animation
const walkFrames = spriteAtlas.sub(Vec.from(0,0,64,8)).split(8);

Members

clip :Core.Vec

The clip of the Tile. In other words: the visible part of the image.

texture :Texture

The Texture behind this Tile.

Methods

grid(width, height, gap) :Core.Tile

Horizontally and vertically splits the current tile in sub tiles. All returned tiles make use of the same texture but have different visible areas of it.
Parameters:
Name Type Default Description
width number The width of a single sub tile
height number The height of a single sub tile
gap number 0 The gap between 2 sub tiles in the texture
Returns:
The splitted Tiles.

split(px, gap) :Core.Tile

Horizontally splits the current tile in sub tiles. All returned tiles make use of the same texture but have different visible areas of it.
Parameters:
Name Type Default Description
px number The width of a single sub tile
gap number 0 The gap between 2 sub tiles in the texture
Returns:
The splitted Tiles.

splitV(px, gap) :Core.Tile

Vertically splits the current tile in sub tiles. All returned tiles make use of the same texture but have different visible areas of it.
Parameters:
Name Type Default Description
px number The height of a single sub tile
gap number 0 The gap between 2 sub tiles in the texture
Returns:
The splitted Tiles.

sub(clip) :Core.Tile

Creates a new Tile with the given visible area.
Parameters:
Name Type Description
clip Core.Vec The visible area of the created texture
Returns:
The created sub Tile.

(static) fromColor(color)

Constructs a new Tile from a given color
Parameters:
Name Type Description
color Core.Vec The color of the tile
Returns:
The tile with the color and the size of one pixel.

(static) fromImage(img) :Core.Tile

Constructs a new Tile from a given html image element as source
Parameters:
Name Type Description
img HTMLImageElement The image of the tile
Returns:
The tile with the full image of the HTMLImageElement.
Example
// create a tile from a HTMLImageElement
const img = document.queySelector("img"); // could be loaded from dom
const tile = Tile.fromImage(img);