Render/Camera help

Hi,

Can someone please explain how to center the player to the middle of the screen and such? I’ve already read the documentation dozens of times, but by the time I start getting to the render part of things everything just begins to fall apart. I’ve already got a working camera file and it’s been childed to the player game object. The problem is, the player is on the bottom left part of the screen and I have no idea how to fix it. Can someone mabye explain step by step the process I am supposed to do? The documentation was a bit too broad for me to understand. (I learn best via examples I guess.)

I tried to fix it myself but now I am getting this nifty little error -
WARNING:RESOURCE: Resource not found: /main/Assets/camera.renderc
WARNING:ENGINE: Unable to load bootstrap data.

To center the view on the camera position you will need to modify your render script. You’ll need to copy the builtin render script into you project folder somewhere so you can modify it. You’ll also need a .render file that points to your render script, and set the bootstrap render to this in your game.project.

There will be a line in the update function where render.set_projection is called, before sprites (self.tile_pred) are drawn. Replace that line with something like this:

    local w = render.get_window_width()
    local h = render.get_window_height()
    render.set_projection(vmath.matrix4_orthographic(-w/2, w/2, -h/2, h/2, -1, 1))

The vmath.matrix4_orthographic function makes an orthographic projection matrix. It takes left, right, bottom, top, near, and far arguments and defines a 3D box in which things will be rendered. So of course, to center it, you need left to be minus half of the window width, right to be plus half the window width, and so on.


I’m not sure the exact conditions that cause that error, but it sounds like you are trying to use a file that isn’t there. You’ll need to sort that out before you can expect things to work correctly.

2 Likes