【问题标题】:Phaser Game Keyboard Arrow Keys to Mobile TouchPhaser 游戏键盘箭头键到移动触摸
【发布时间】:2018-08-17 14:21:56
【问题描述】:

我是 Phaser 的新手,我在这里学习本教程:https://phaser.io/tutorials/making-your-first-phaser-3-game/part7

在手机浏览器上使用需要更改哪些内容才能让播放器在点击屏幕时自动向右运行并跳转?我已经搜索了很长时间,但找不到答案,正在努力学习

//  Input Events
cursors = this.input.keyboard.createCursorKeys();


if (cursors.left.isDown)
{
    player.setVelocityX(-160);

    player.anims.play('left', true);
}
else if (cursors.right.isDown)
{
    player.setVelocityX(160);

    player.anims.play('right', true);
}
else
{
    player.setVelocityX(0);

    player.anims.play('turn');
}

if (cursors.up.isDown && player.body.touching.down)
{
    player.setVelocityY(-330);
}

【问题讨论】:

    标签: phaser-framework


    【解决方案1】:

    我会做什么:

    向您的一般游戏添加一个输入处理程序,当指针向下时调用“跳转”函数。

    this.input.on('pointerdown', this.jump, this);
    

    Jump 现在应该验证玩家可以跳跃。比如:

    jump() {
      if (this.player.body.touching.down) {
        this.player.setVelocityY(-330);
      }
    }
    

    要让您的播放器自动以一定速度移动,您可以在创建播放器时设置播放器的身体速度。

    this.player.body.velocity.x = 160;
    

    请注意,如果您想保持当前控制player 的能力,另一种选择是在屏幕上设置实际按钮,用户可以点击/单击以使player 相应地移动/动作。有一个 official plugin for Phaser 2 可以做到这一点,你可以看看。

    【讨论】:

    猜你喜欢
    • 2022-01-26
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    相关资源
    最近更新 更多