【问题标题】:Phaser 3 Arcade: Setting Y of camera following player to fixedPhaser 3 Arcade:将摄像机跟随玩家的 Y 设置为固定
【发布时间】:2019-09-23 21:59:31
【问题描述】:

我从一个无尽的跑步游戏开始,玩家的位置是固定的,物体向左移动。我使用camera.startFollowing(player) 跟随玩家,但是当我跳跃时,相机会随着玩家移动。但是相机的 Y 位置必须是固定的。

尝试通过setFollowOffset(); 设置偏移量并且我尝试使用碰撞物理但Phaser 找不到this.impact。 我使用 Phaser 3。

我已经从下面的代码 sn-p 中删除了不相关的代码。

var player, ground, camera;
function create(){
   ground = this.physics.add.image(0, 568, 'ground').setScale(2, 2).setGravity(0);
   player = this.physics.add.sprite(100, 510, 'dude');
   player.setBounce(0);
   ground.setCollideWorldBounds(true);
   this.physics.add.collider(ground, player);
   camera = this.cameras.main;
   camera.startFollow(player);
   camera.setFollowOffset(-300, 225);
}

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


var config = {
   type: Phaser.AUTO,
   width: 800,
   height: 600,
   backgroundColor: '#ffff9c',
   physics:{
      default: 'arcade',
      arcade:{
         gravity: {y: 600},
         debug: false,
      }
   },
   scene:{
      preload: preload,
      create: create,
      update: update
   }
};

var game = new Phaser.Game(config);

【问题讨论】:

  • 有人可以帮帮我吗?

标签: javascript phaser-framework


【解决方案1】:

已解决,我补充:

camera.setLerp(0,0);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多