Phaser 2 How can i use Animation with Phaser.sprite.call

145 views Asked by At

How can I use animations with Phaser when I'm using Phaser.Sprite.call? Phaser is giving me the error:

phaser.min.js:19 Uncaught TypeError: Cannot read property 'add' of undefined
    at new c.Animation (phaser.min.js:19)

I Googled so long for a solution but didn't find anything.

Here is my code:

var Enemy = function(game, x, y) {
    Phaser.Sprite.call(this, game, x,y,'Enemy');
    game.physics.enable(this, Phaser.Physics.ARCADE);
    this.enableBody = true;
    this.body.gravity.y = 400;
    var walk = this.animations.add('walk');
    this.animations.play('walk', 4, true);
    this.anchor.setTo(0.5, 0.5);
    this.scale.setTo(0.15);
    this.body.velocity.x = -60;
    this.health = 4;
    this.maxHealth = 4;
}
Enemy.prototype = Object.create(Phaser.Sprite.prototype);
Enemy.prototype.constructor = Enemy;
0

There are 0 answers