Skip to content
Advertisement

Phaser 3: load spritesheet for animation with unequal dimensions

Im trying to work with the phaser 3 framework.

In order to load a spritesheet and create its animation I first load the spritesheet:

this.load.spritesheet('player', 'assets/spritesheets/player.png',{frameWidth:16,frameheight:16});

then I create the animation as follows:

JavaScript

This works fine but if I have unequal dimensions such as

JavaScript

I receive the following error:

JavaScript

if i print console.log(this.anims.generateFrameNumbers("player"));

the output is:

JavaScript

however for the unequal dimension sprite I get an empty array.

In Phaser’s Documentation it seems to be okay to use different dimensions for a spritesheet.

Any help or pointers would be much appreciated.

Edit Here are thee images I tried using

1health.png

1health.png

Advertisement

Answer

Everything works fine for me, here is how I display a sprite in a scene:

In loading.js:

JavaScript

Gameplay:

JavaScript

enter image description here

But you have two exactly same frames, so I don’t understand what you are trying to do? Switching between those frames does not make any difference, there is always one red and two black hearts.

Maybe you don’t need any animation, you can set frame using:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement