gpt4 book ai didi

javascript - Phaser 3 街机 : Setting Y of camera following player to fixed

转载 作者:行者123 更新时间:2023-11-28 03:32:28 25 4
gpt4 key购买 nike

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

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

我已从下面的代码片段中删除了不相关的代码。

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);

最佳答案

解决了,我补充一下:

camera.setLerp(0,0);

关于javascript - Phaser 3 街机 : Setting Y of camera following player to fixed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58051157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com