How to render the game world off-centre and in a subset of the screen?

I’m wondering how to set up rendering to achieve a game world that is off-centre, for a game that is mostly UI (see image below). The specific resolution numbers aren’t important, the main idea is that I want to have the game world off-centre.

The ideal solution would be that in terms of my programming of the game world, it’s as if the whole project is 300x300 starting at 0x0 (not whatever the offset position is in my image below). I don’t want to have to amend any game logic to account for this, if that makes sense. With a tweak of the render script, the position of the game world should be able to be changed, without affecting the game logic.

I tend to use Rendercam but would be happy to hear a solution that uses Orthographic as well.

Bonus: Would the considerations change for a pixel perfect retro style? For example, handling different resolutions.

Thanks!

2 Likes

One day messing with the render script I did something similar to what you want, but at this point I can’t quite remember nor explain how I did it XD. I’m gonna stick around and see how the pros would do it.

1 Like

I wrestled Fates of Ort into doing what I needed it to do, but it was a bad solution that caused me no end of grief throughout the development process. This isn’t the same scenario exactly but nevertheless, I would love to hear a good way to achieve this so I can do this project right. :slight_smile:

1 Like

Something like this?

2 Likes

Yes, I think so. I’ve read that post but not got deeply into it. Spent some time tonight looking at lowrezjam template, the render manual, and the documentation of both rendercam and orthographic. My head is spinning but I’m none the wiser :slight_smile:

I think what’s achieved in Hook, Line and Thinker is basically exactly what I’m asking about, though the UI solution is concerning as I’d normally like to use GUI objects for UI. In addition, I see there is some camera panning (e.g. on loading a new level), but I’m not sure the camera functionality described there is as complex as what I’m asking about (i.e. integration with rendercam or orthographic).

I’m happy to spend more time trying to figure this out, but if anyone has any other pearls of wisdom at this stage then I’m all ears!

If you look at the render script there’s three things that is set up before drawing anything:

  • The view using render.set_view(view_matrix)
  • The projection using render.set_projection(proj_matrix)
  • The viewport using render.set_viewport(x,y,w,h)

The view and projection is continuously updated by the camera you use (or set to fixed values in the render script init() function).

The viewport on the other hand is usually fixed and set to span the entire size of the screen. You should be able to change this to render in the area where you have the “game world” in your mockup above and call render.draw() to draw your sprites etc like normal.

You then need to reset the viewport to render on the entire screen before calling render.draw() on your gui.

4 Likes

@Alex_8BitSkull in my render_script I have the line:

render.set_viewport(left_corner, bottom_corner, viewport_width, viewport_height)

that I use in case the aspect ratio is so extremely tall I need to implement a letter box. If you need any help in this please ask.

2 Likes