Reputation: 315
I'm trying to have an eight-frame walking animation of a character in my game.
This is the code that loads the sprite sheet:
this.load.spritesheet('PeefSide', "assets/PeefSide.png", {frameWidth: 50, frameHeight:
60, startFrame: 0, endFrame: 7});
This is the code that creates the sprite:
this.p1 = this.physics.add.sprite(500, 730, 'PeefSide');
This is the code that creates the animation:
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNumbers('peefSide', { start: 0, end: 7, first: 0}),
frameRate: 10,
repeat: -1
});
And this is the code that plays the animation when the character moves:
if(this.keyA.isDown) {
this.p1.setVelocityX(-200);
this.p1.anims.play('walk', true);
}
I'm not sure what I've done wrong, but when I run the game, it freezes when I press a move button. The inspection screen says that the error is trying to read properties of undefined and before the error occurs, it says:
generateFrameNumbers: Frame 0 missing from texture: peefSide
It repeats this line for every frame, the number going up one, then the game freezing error happens when a move button is pressed. Really not sure what went wrong.
If it helps find an answer, I'm using Phaser 3 in VSCode employing arcade physics.
Upvotes: 2
Views: 387
Reputation: 14695
The problem is, that the key used in this.anims.generateFrameNumbers('peefSide',...)
, doesn't match the actual key from the load this.load.spritesheet('PeefSide',...)
, because the key is case-sensitive.
You would have to use the UpperCase 'P' like this this.anims.generateFrameNumbers('PeefSide',...)
This should fix the Warning:
generateFrameNumbers: Frame 0 missing from texture: peefSide
And this will also solve the freezing issue, because now the animation will be actually playing, before because it culdn't find the frames, it showed the initial frame.
Upvotes: 0