Sprite from Tilemap Texture
Demonstrates how to manually parse a loaded image into a SpriteSheet at runtime, allowing you to create Sprites from individual tiles.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('fantasy', 'assets/tilemaps/tiles/fantasy-tiles.png');
}
create ()
{
const tiles = this.textures.get('fantasy');
const base = tiles.get();
Phaser.Textures.Parsers.SpriteSheet(tiles, base.sourceIndex, base.x, base.y, base.width, base.height, {
frameWidth: 64,
frameHeight: 64
});
this.add.sprite(200, 300, 'fantasy', 6);
this.add.sprite(300, 300, 'fantasy', 24);
this.add.sprite(400, 300, 'fantasy', 28);
this.add.sprite(500, 300, 'fantasy', 31);
this.add.sprite(600, 300, 'fantasy', 49);
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);