Javascript Phaser 2如何在Phaser.sprite.call中使用动画

Javascript Phaser 2如何在Phaser.sprite.call中使用动画,javascript,phaser-framework,Javascript,Phaser Framework,当我使用Phaser.Sprite.call时,如何使用带有Phaser的动画?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
时,如何使用带有
Phaser
的动画?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;

您使用的是什么版本的移相器?你如何将精灵添加到游戏中?使用稍旧版本的Phaser 2 CE,当我尝试您的代码时,这似乎可以正常工作。我使用Phaser v2.6.2,我使用Phaser.sprite.call中的键添加我的精灵(这个,游戏,x,y,“键”)。我先预装了,但没什么帮助。对不起,我的意思是,你是如何将你的敌人添加到游戏中的。将我的测试更新为2.6.2,您的代码似乎运行良好:可能还有其他问题?如果你注释掉动画部分,它是否如预期的那样工作?当我注释掉动画部分时,它工作得非常好。我只是通过创建一个新的敌人()并将其添加到我的敌人组来添加我的敌人。this.enemys.add(新敌人(this,this.game.width,510));