Phaser 2 Как я могу использовать анимацию с Phaser.sprite.call - PullRequest
0 голосов
/ 27 июня 2018

Как я могу использовать анимацию с Phaser, когда я использую Phaser.Sprite.call? Phaser дает мне ошибку:

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

Я так долго гуглил решение, но ничего не нашел.

Вот мой код:

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;
...