Which is the correct way to select only one sprite of spritesheet?

H guys
I want to change the shape of my “player” arround the game.
Which is the correct way to select only one sprite of spritesheet ?
I just need one sprite. no anims.
thks in advance

//preload
 this.load.spritesheet('player', 'assets/dude.png', { frameWidth: 32, frameHeight: 48 });  

//create
player = this.physics.add.sprite(400, 450, 'player', {start: 0, end: 1});

Hi @tijuinem,
This is the constructor of a sprite:
https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Sprite.html#Sprite__anchor
In your case, Assuming that the sprite is the frame 5:

player = this.physics.add.sprite(400, 450, 'player', 5);

If you want to change the frame during the game:

player.setTexture( 'player', 5);

Regards.

2 Likes

oooooh !! thks a lot
it works !!!

ps. creo que si me llegas a contestar en español, nos entendemos también XD.

Sprites also have a setFrame method which allows you to set the frame without specifying the texture again: sprite.setFrame(5).

1 Like