Creating Animations to be used by container and factory sprites

Greetings dood!

In my latest conquest to become ruler of the Prinny Squad I have been trying to create a video game based on an example! The example is a very basic adventure game from Zenva (which has what feels like a really weird structure but it works).

But! I want to add animations to every enemy which is spawned by a factory function and to the player. I thought the best way to do this would be to create the animations in the main game scene. Then have the individual monsters access the relevant animations through their creation method. Unfortunately, while I can console.log the name of the animation without issue, when I try to use this.anims.play(animationName) the result is “cannot read property play of undefined”

Any help dood?

How are the enemy sprites actually created? I don’t see it happening in EnemyCreate.

The sprites are created in the Enemy class.

I can get the animations working as they should in the GameScene but even if I try passing the animations on to EnemyCreate I get the same error.

Hi,
Here’s how i make a class with anims working

class Player extends Phaser.GameObjects.Sprite {
  constructor(scene, x, y, config) {
    super(scene, x, y, config.key);
  ......
  this.anims.play('anim-name', true);
  }

  preUpdate(time, delta) {
    super.preUpdate(time, delta);
  }

}

The preUpdate with super is what make it works !!

Hope this helps…

Someone found what the problem was for me!
Animation Fix