简体   繁体   English

在 Ursina Engine 中锁定相机?

[英]Locking the camera in Ursina Engine?

I am creating a 2d mario style platformer using Ursina Engine, and I want to be able to lock the camera when the player goes left and stop the camera from tracking just the player.我正在使用 Ursina 引擎创建一个 2d mario 风格的平台游戏,我希望能够在玩家向左移动时锁定相机并阻止相机只跟踪玩家。 I looked through the documentation and it seems pretty barren.我查看了文档,看起来很贫瘠。 Anyone work with this game engine yet?有人用过这个游戏引擎吗?

You can set the camera position and rotation just like with any other Entity.您可以像设置任何其他实体一样设置相机位置和旋转。 This code will limit x to 0:此代码将 x 限制为 0:

camera.x = max(camera.x, 0)

Or if you've parented the camera, you may want to set world position instead:或者,如果您已经设置了相机的父级,您可能希望改为设置世界位置:

camera.world_x = max(camera.world_x, 0)

You could use an if statement to clarify what you want and use a previous_x variable.您可以使用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

So...所以...

By using an if statement , you can create a function using a variable as a flag .通过使用if语句,您可以创建一个使用variable作为flag的函数。 Checking this allows you to lock the camera.选中此项可让您锁定相机。

Just add camera.position and camera.rotation:只需添加 camera.position 和 camera.rotation:

camera.position=(1, 10, -10)
camera.rotation=(1, 10, -10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM