Constructor
new Map(sheet, data)
- Source:
Initiates new Tilemap.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sheet |
Pixel.SpriteSheet#sheet | Pixel.SpriteSheet#generateSheet | The spritesheet used for the tilemap. | |||||||||||||||
data |
object | The data object for the tilemap.
Properties
|
Extends
Members
anchor :Pixel.Point
- Source:
- Overrides:
The anchor position of the sprite.
Type:
deg :number
- Source:
- Overrides:
- Default Value:
- 0
The degress of rotation on the sprite.
Type:
- number
flipX :boolean
- Source:
- Overrides:
- Default Value:
- false
Determines if the sprite is flipped over the x axis.
Type:
- boolean
flipY :boolean
- Source:
- Overrides:
- Default Value:
- false
Determines if the sprite is flipped over the y axis.
Type:
- boolean
height :number
- Source:
- Overrides:
Height of the Sprite's hitbox.
Type:
- number
id :string
- Source:
- Overrides:
- Default Value:
- 0
The id of the sprite, used to find sprites when deleting them.
Type:
- string
opacity :number
- Source:
- Overrides:
The opacity of the sprite.
Type:
- number
point :Pixel.Point
- Source:
- Overrides:
The position of the sprite.
Type:
scale :number
- Source:
- Overrides:
- Default Value:
- 1
The scale of the sprite (0 --> 1).
Type:
- number
tiles :Array.<Array.<number>>
- Source:
Tilemap array.
Type:
- Array.<Array.<number>>
width :number
- Source:
- Overrides:
Width of the Sprite's hitbox.
Type:
- number
x :number
- Source:
- Overrides:
X position.
Type:
- number
y :number
- Source:
- Overrides:
Y position.
Type:
- number
Methods
applyTileset(tiles)
- Source:
Applies a pre-determined tileset to the tilemap.
Parameters:
Name | Type | Description |
---|---|---|
tiles |
Array.<Array.<number>> | Array of tiles. |
checkCollisions(rect2)
- Source:
Checks collisions with a sprite.
Parameters:
Name | Type | Description |
---|---|---|
rect2 |
Pixel.Sprite | Sprite that tilemap checks to see if it is colliding with. |
collideByExclusion(ids)
- Source:
Sets collisions by excluding x ids.
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array.<number> | IDs of every tile that cannot collide. |
copy(sprite)
- Source:
- Overrides:
Copy the value of another sprite onto this one.
Parameters:
Name | Type | Description |
---|---|---|
sprite |
Pixel.Sprite | Sprite who's values this will copy. |
fill(id, gx, gy, w, h)
- Source:
Fills area with 1 tile.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | ID of tile. |
gx |
number | Start x of fill. |
gy |
number | Start y of fill. |
w |
number | Width of fill. |
h |
number | Height of fill. |
generateBlankMap()
- Source:
Generates a blank tilemap.
placeTile(id, x, y)
- Source:
Places single tile at TileX and TileY.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | ID of tile. |
x |
number | TileX of tile. |
y |
number | TileY of tile. |
placeTiles(tilesArray, x, y)
- Source:
Places multiple tiles horizontally + vertically based on array.
Example
// Create new map
var map = new Pixel.Map(Pixel.SpriteSheet.generateSheet(), { // Use an existing sprite sheet to pass to the map
width: 48,
height: 48,
tileWidth: 48,
tileHeight: 48
});
// Generate a blank map
map.generateBlankMap();
// Place tiles on the map
map.placeTiles([ [10], [50], [32] ], 5, 5); // Is vertically, starting at tile index 5, 5
map.placeTiles([ 10, 50, 32 ], 5, 5); // Is horizontally, starting at tile index 5, 5
Parameters:
Name | Type | Description |
---|---|---|
tilesArray |
Array.<number> | Array.<Array.<number>> | Array of tiles to be placed. |
x |
number | X position of first tile. |
y |
number | Y position of first tile. |
render(ctx)
- Source:
Renders the tilemap.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2d | The Canvas to print to. |
reset(ctx)
- Source:
- Overrides:
Resets settings set on sprite.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2d | Context to reset settings on. |
setAnchor(x, y)
- Source:
- Overrides:
Set the position the sprite is anchored to (0-->1).
Parameters:
Name | Type | Description |
---|---|---|
x |
number | X position, scale of 0 to 1. |
y |
number | Y position, scale of 0 to 1. |
setSize(w, h)
- Source:
- Overrides:
Sets the hitbox size of the sprite.
Parameters:
Name | Type | Description |
---|---|---|
w |
number | Width. |
h |
number | Height. |
settings(ctx)
- Source:
- Overrides:
Applies settings set on sprite.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2d | Context to apply settings to. |
spin(num)
- Source:
- Overrides:
Spins x * 360 degrees.
Parameters:
Name | Type | Description |
---|---|---|
num |
number | Amount of times sprite rotates 360 degrees. |
tileToWorldX(x)
- Source:
Converts tile to world x.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | TileX. |
tileToWorldY(y)
- Source:
Converts tile to world y.
Parameters:
Name | Type | Description |
---|---|---|
y |
number | TileY. |
weightedRandomize(gx, gy, w, h, index)
- Source:
Randomly places tiles based on weight.
Example
// Example of weightedRandomize use, where map is a Pixel.Map
map.weightedRandomize(10, 10, 10, 10, [{index: 4, weight: 3}, {index: 10, weight: 0.5}]);
Parameters:
Name | Type | Description |
---|---|---|
gx |
number | Starting tile x. |
gy |
number | Starting tile y. |
w |
number | Tile width (amount going across). |
h |
number | Tile height (amount going down). |
index |
Array.<object> | All indexes + weights of ids to place. |