我正在尝试制作游戏来学习移相器,但我的精灵并没有移动。这是代码:
Player.prototype.update = function() {
game.physics.arcade.collide(this, walls);
this.moving = false;
if (cursors.up.isDown) {
this.direction = Entity.prototype.directions.BACKWARD;
this.moving = true;
} else if (cursors.down.isDown) {
this.direction = Entity.prototype.directions.FORWARDS;
this.moving = true;
} else if (cursors.left.isDown) {
this.direction = Entity.prototype.directions.LEFT;
this.moving = true;
} else if (cursors.right.isDown) {
this.direction = Entity.prototype.directions.RIGHT;
this.moving = true;
}
this.requiredFunctions();
};
播放器从GameObject继承自Entity和Entity。这是来自实体的相关代码:
Entity.prototype.requiredFunctions = function() {
this.physics();
this.statusEffects();
this.move();
this.animate();
if(debugMode) {
this.game.debug.spriteBounds(this);
}
};
我已经使用console.log(this.body.velocity.x + ", " + this.body.velocity.y)
进行了检查,并且在更新结束时速度不是0,0(如果我按了一个键)而且,当我尝试放置this.body.velocity.x = 100;
时(或者任何其他数字)最后,玩家精灵仍然不动!有没有明显的解决方案,如果您需要更多代码,请说明。