I decided to give Phaser a try but am a bit confused at how to go about selecting specific portions of a spritesheet.
All of the sprite animation tutorials I find only show how it is done from a sprite sheet that contains just the character sprite and iterates on the x-axis. If I have a large sheet with all of the sprites how can I use just a few frames for my character?
What I need is to select frames 1001 to 1006 (at least I hope thats how they are calculated) and tried the following:
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('tilemap', { start: 1001, end: 1006 }),
frameRate: 100,
repeat: 0 //also tried -1
});
I also tried adding a start and end to my player declaration
player = this.physics.add.sprite(32, 32, 'tilemap', { start: 1001, end: 1006 });
What happens though is the whole sheet appears on the screen and flickers.
Here’s an image of the sheet
And here is my create()
:
function create () {
let map = this.make.tilemap({ key: 'map' });
let tiles = map.addTilesetImage('kingdom_crawl_tileset', 'tilemap');
let groundLayer = map.createLayer('Ground', tiles, 0, 0);
let wallLayer = map.createLayer('Walls', tiles, 0, 0);
player = this.physics.add.sprite(32, 32, 'tilemap');
player.setCollideWorldBounds(true);
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('tilemap', { start: 5, end: 10 }),
frameRate: 100,
repeat: 0 //also tried -1
});
keyboard = this.input.keyboard.createCursorKeys();
}
thanks in advance