Load a pre-packed texture atlas and repack it onto texture sheets
- Supports TexturePacker json (hash and array) and Aseprite json
- Returns an empty object which is filled with TileInfos when loaded
- Frames are named by the json, animations are grouped automatically
- Aseprite frame tags become animations, so do names like run_0, run_1
- Trimmed frames are restored to their full source size when packed
- Rotated frames are rotated back upright when packed
- The same atlas loaded again by its paths, with the same padding, gives back what the first load did, packed
once, unless that load failed
imageSrc stringAtlas image path
jsonSrc string|ObjectAtlas json path, or already parsed json data
padding number optionalHow many pixels padding around each frame
- Returns
Object mapping frame and animation names to TileInfos
const atlas = loadAtlas('sprites.png', 'sprites.json');
await spritesReady();
drawTile(pos, size, atlas.player); // a single frame
drawTile(pos, size, atlas.run.frame(2)); // frame 2 of the run animation
Load an image and pack it into a texture sheet
- Returns a TileInfo immediately which is filled in when the image loads
- Nothing is visible until it loads, use spritesReady to wait for it
- Pass frameSize for animations, then step through them with TileInfo.frame
- Grid images keep their layout and frames wrap down to the next row
- Pass sourcePadding if the source image has padding baked in around frames
- The same image loaded again with the same settings gives back what the first load did, packed once, unless
that load failed
src stringImage source path
frameSize Vector2|number optionalSize of each animation frame in pixels, or the whole image less its
source padding if not passed
padding number optionalHow many pixels padding around each frame
sourcePadding number|Vector2 optional, default 0How many pixels padding around each frame in the source image
const playerTile = loadSprite('player.png'); // a single sprite
const runTile = loadSprite('run.png', vec2(16)); // a 16x16 frame animation
Load tile images and pack them into texture sheets as one tile set, for tile layers and maps
- Each image is cut into tiles of tileSize, left to right then down, so an image of one tile is one tile and a
sheet is all of its tiles; the tiles are numbered from 0 in the order the images are given
- Returns a tile set at once, a TileInfo whose tiles fill in as the images load; wait for them with spritesReady
- Give it to tileLayersLoad, a TileLayer or a TileCollisionLayer as its tile info: tile n draws tiles[n],
wherever it was packed, and the level editor's palette offers each of them; frame and index do not read the
list, use set.tiles[n] for one tile; make the layers after spritesReady, a layer made before draws nothing
- An image that is not a whole number of tiles gives the whole tiles in it; a sheet with gaps between its tiles
is not read, cut it into its tiles first
- An image that fails to load, or that no sheet can hold, adds no tiles and says so in the console, so the tiles
of the images after it move up
- The same images loaded again with the same settings give back what the first load did, packed once, unless
an image of it failed
sources Array<string>Image source paths
tileSize Vector2|number optionalSize of a tile in pixels
padding number optionalHow many pixels padding around each tile on the sheet
const tiles = loadTiles(['grass.png', 'dirt.png', 'water.png', 'props.png'], 16);
await spritesReady();
tileLayersLoad(map, tiles); // tile 0 is grass, 1 dirt, 2 water, then the tiles of props.png
Parse atlas json into a list of named frame groups, used by loadAtlas
- Accepts TexturePacker json (hash and array) and Aseprite json
- Frames tagged in Aseprite or named like run_0, run_1 group into animations
data ObjectParsed atlas json data
- Returns
List of {name, frames} groups in atlas order
Wait for everything started by loadSprite and loadAtlas to finish packing
async function gameInit()
{
playerTile = loadSprite('player.png');
runTile = loadSprite('run.png', vec2(16));
await spritesReady();
}
Array of texture sheets created by loadSprite