我正在使用Ursina引擎创建一个2D马里奥风格的平台游戏,我想在玩家向左移动时锁定相机,并停止相机跟踪玩家。我查看了文档,但似乎很贫乏。有人已经使用过这个游戏引擎吗?
您可以像设置其他实体一样设置相机的位置和旋转。以下代码将限制x为0:
camera.x = max(camera.x, 0)
或者,如果您已经让相机成为其他对象的子对象,则可能希望设置世界位置:
camera.world_x = max(camera.world_x, 0)
只需添加 camera.position 和 camera.rotation:
camera.position=(1, 10, -10)
camera.rotation=(1, 10, -10)
if
语句来澄清你想要的,并使用一个 previous_x
变量。 prev_x = camera.x
def update(): #the following code should be added to your update function which is already called...
if prev_x < camera.x:
lock()
#this should be a function which is linked
#to your code which moves the camera.
#A way to do this would be to set a
#certain variable to true and use the following code:
locked = False
if not locked:
function_which_moves_camera_left()
#The lock() function would be:
def lock():
locked = True
#You could unlock it with the function:
def unlock():
locked = False