我在摄像头方面一直在参考这个教程,但搞不懂为什么摄像头Y轴无法正常工作。
当我在屏幕最左侧角落时,摄像头会向上移动并远离玩家。在关卡/房间的其他位置,玩家向上移动时摄像头也不会跟随。
非常感谢任何帮助!另外,在这个编程阶段,我的房间切换不知为何也失效了。可能和改变房间大小有关?
这是我的摄像头代码:
create:
cam = view_camera[0] //命名房间摄像头
cam_followspeed = 16 //数值越低跟随越快
follow = oEmil //玩家对象
width_half = camera_get_view_width(cam) * 0.5 //计算摄像头中心
height_half = camera_get_view_height(cam) * 0.5
xTo = x
yTo = y
step:
//更新目标位置
if (instance_exists(follow)) {
xTo = follow.x
yTo = follow.y
}
//更新对象位置
x += (xTo - x) / cam_followspeed //摄像头离对象越近移动越慢
y += (yTo - y) / cam_followspeed
//防止摄像头离开房间
x = clamp(x,width_half,room_width-width_half)
y = clamp(x,height_half,room_height-height_half)
//更新摄像头视图
camera_set_view_pos(cam,x-width_half,y-height_half)
评论 (0)