JS Phaser - 为什么我的精灵不动

时间:2016-06-20 07:00:13

标签: javascript debugging phaser-framework

我正在尝试制作游戏来学习移相器,但我的精灵并没有移动。这是代码:

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;时(或者任何其他数字)最后,玩家精灵仍然不动!有没有明显的解决方案,如果您需要更多代码,请说明。

0 个答案:

没有答案