I created a texture atlas with different characters sprites for my game. One of the character has two sprites for walking, named “player_walk1.png” and “player_walk2.png”.
Here’s my code for loading the texture atlas (in preload) : this.load.atlas('my_sprites','assets/my_sprites.png', 'assets/my_sprites.json');
Her’es my code for adding the player : this.player = this.add.sprite(200, 470, 'my_sprites','player_stop.png');
And here’s my animation this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers('my_sprites', {prefix:'player_walk', start: 1, end: 2 }), frameRate: 10, repeat: -1 });
When I call this animation with my cursors in the update, I got this error message in the console
Uncaught TypeError: Cannot read property ‘frame’ of undefined
I think I’m miswriting the this.anims.generateFrameNumbers. Any help for a quick fix or maybe a link to a good example?
By the way, I do have a side question. If it looks more complex, I’ll create a specific post.
What if I want to create an animation (going left) with the same sprites flipped? Should I add them reversed in the Texture atlas or is there an easy way to reuse them?
I spent much more time on this error than I’d like to admit, so I hope I will at least help some lost dev that ends up here. The problem was that I had frame instead of frames in animation config.