0
votes

I have a small issue that and I’m not able to figure out what’s wrong, maybe someone can help.

It seems player.anims.play(‘walk’) is not working I get an error which reads “Cannot read property ‘frame’ of undefined”.

It seems I get an empty array of frames.

How I load my spreadsheet in preload():

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

How my class looks :

export default class Player extends Phaser.Physics.Arcade.Sprite {
  constructor(scene: Phaser.Scene, x: number, y: number) {
    super(scene, x, y, 'player')
    const player = scene.physics.add.sprite(x, y, 'player')
    player.setCollideWorldBounds(true).setInteractive()

    scene.anims.create({
      key: 'walk',
      frames: scene.anims.generateFrameNames('player', { start: 1, end: 3 }),
      repeat: -1
    })

    player.anims.play('walk')
  }
}

in create():

this.player = new Player(this, 10, 10)
1
Found the solution myself I’m using Phaser 3.21.0 and it seems that inside this.load.spritesheet I have to pass endFrame inside config object - Rokas Simkus

1 Answers

0
votes

Found the solution I’m using Phaser 3.21.0 and it seems that inside this.load.spritesheet I have to pass endFrame inside config object