gameify. Tileset

A Tileset for use with Tilemaps, Sprites, etc

Constructor

new Tileset(path, twidth, theight)

Parameters:
NameTypeDescription
pathString

The image/tileset filepath

twidthNumber

The width of each tile

theightNumber

The height of each tile

Example
let myTileset = new gameify.Tileset("images/tileset.png");
// Give the coordinates of a tile to retrieve it
let grassTile = myTileset.getTile(3, 2);

Members

(package) texture

The tileset's image/texture

(readonly) theight

The Tilemap's tile height

(readonly) theight

The Tileset's tile height

(readonly) twidth

The Tilemap's tile width

(readonly) twidth

The Tileset's tile width

Methods

changePath(path)

Change and load a new image path. Please note this does not clear tilemaps' cached data, and it might retain its the original image.

Parameters:
NameTypeDescription
pathstring

The new tileset image path

fromJSON(data, ref) → {gameify.Tileset}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
gameify.Tileset

getTile(x, y, widthopt, heightopt) → {gameify.Image}

Get a tile (or section of tiles) from the tileset. Returns a new Image object each time, so if you're getting the same tile a lot you might want to save it to a variable

Parameters:
NameTypeAttributesDefaultDescription
xNumber

The x coordinate of the tile

yNumber

The y coordinate of the tile

widthNumber<optional>
1

How many tiles wide

heightNumber<optional>
1

How many tiles tall

Returns:
Type: 
gameify.Image

onLoad(callback)

Set a function to be run when the image is loaded

Parameters:
NameTypeDescription
callbackfunction

The function to be called when the image is loaded.

removeCollisionShape(tilex, tiley)

Remove a collision shape from the tileset

Parameters:
NameTypeDescription
tilexNumber
tileyNumber

removeCollisionShape(tilepos)

Remove a collision shape from the tileset

Parameters:
NameTypeDescription
tileposgameify.Vector2d

setCollisionShape(shape, tilex, tiley)

Add a collision shape to the tileset

Parameters:
NameTypeDescription
shapegameify.shapes.Shape
tilexNumber
tileyNumber

setCollisionShape(shape, tilepos)

Add a collision shape to the tileset

Parameters:
NameTypeDescription
shapegameify.shapes.Shape
tileposgameify.Vector2d

toJSON(keyopt, ref) → {Object}

Convert the object to JSON

Parameters:
NameTypeAttributesDescription
keystring<optional>

Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
Object