Gui position not independent?

UPDATE:
I realized its my render script that is causing the problem :man_facepalming: . So its actually my fault. You can mark this as resolved.

I’m using @britzl’s camera library to follow the player. While I don’t think the camera is the issue, for some reason the gui is moving relative to the player. I tried adding the gui directly as a child to the player game object, but it still shows up in the wrong place (player’s y position is 1000 pixels). The behavior I am expecting is the gui remains at the origin (0,0) relative to the screen at all times.

According to the docs, it looks the gui’s position should be independent of everything else? I’m super confused :confused:

Yes, this is absolutely correct. The gui should not move, even if it’s childed to a game object that is moving around. The gui should be rendered in screen space, not world space.

Did you render the gui in world space?

I’m not exactly sure what world space means. I currently have it as a game object at the root of the collection. I did notice that calling render.set_view(vmath.matrix4()) before rendering the gui fixed it.

Yes, this makes sense. If you take a look at the default render script you see to sets of render calls. One draws sprites/tiles, spine etc in world space. The second set of render calls resets the view and projection to screen space, meaning that everything is rendered with bottom left corner being 0,0.

1 Like

Ah ok, so if I’m understanding this correctly, self.view represents the game / world space, and setting it to a zero state resets the view to screen space?

There’s three concepts in the render script:

  1. Viewport - This is the area of the screen to render. Set using render.set_viewport().
  2. View - Created from the position of the camera, the direction the camera is facing and an up-vector (to define what is up and what is down). Created using vmath.matrix4_look_at() and set using render.set_view().
  3. Projection - This is how the view is rendered. Orthographic (typically 2D) or perspective (3D). For orthographic there’s the possibility of rendering stretched, zoomed, fixed fit etc. Near and far z planes are also defined in the projection. Created using vmath.matrix4_orthographic() or vmath.matrix4_perspective() and set using render.set_projection().

The view combined with the projection defines what is seen on screen.

When the view is set to vmath.matrix4() the documentation states that it is a “transform with no translation or rotation.”

And when I talk about screen space I mean a view and projection that is rendered without any translation or rotation to match the screen. Meaning that something positioned at 0,0 is rendered in the lower left corner.

World space on the other hand is how the game world is rendered. Take a top-down shooter for instance with a large game world with a camera that follows the player. This means that something positioned at 0,0 in the game world likely isn’t positioned in the lower left corner since the camera is moving with the player. Defold-Orthographic and RenderCam provides functions to convert from screen to world coordinates and vice versa. This is useful when you want to translate a click on the screen into a world space coordinate for instance.

3 Likes

Thanks for the thorough explanation. I’m starting to get a better handle of the rendering pipeline.