Phaser Can't spawn a sprite from a sprite sheet correctly

Viewed 47

I made an 8-frame sprite sheet to use in a walking animation, and I'm trying to use the sprite sheet to spawn a single frame to use when the character isn't moving.

This is the code I'm using to load the sprite sheet:

this.load.spritesheet('PeefSide', "assets/PeefSide.png", {frameWidth: 50, frameHeight: 
60});

And this is the code that I'm using to spawn a single sprite:

this.p1 = this.physics.add.sprite(1535, 730, 'PeefSide');

But for some reason, instead of a single sprite, the entire sprite sheet spawns in the level. I'm not sure what I did wrong, so can someone provide a solution?

If it helps, I'm using phaser 3 in VSCode with arcade physics.

1 Answers

The problem is, that the frame-size of the phaser-spritesheet is too big (or the actual image, that is loaded, is to small).

Check the frame-size (frameWidth and frameHeight) from the this.load.spritesheet(...), with the actual image size, and alter the images size, so that the image width and height is exact multiple of the frameWidth and frameHeight, this should solve your problem.

Similar as mentioned in this answer

Related