Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Accommodating different resolutions in 2D games  (Read 1866 times)

0 Members and 1 Guest are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Accommodating different resolutions in 2D games
« on: October 07, 2018, 11:41:01 am »
My current method for giving players more resolution options other than the "native" one - native being the resolution that the art assets were designed for - is to draw everything on a RenderTexture, call setSmooth(true) for it, and give the player various size options for window creation.

My first question is: Is this the only viable option? What other options are there and which do you prefer? Especially considering that the method I use is only good for resolutions of the same ratio.

My next question is regarding a problem that I'm facing with this method. The characters in my game are relatively small (140 pixels in height in native 1080p resolution), and so are their health bars (50 pixels wide, 6 pixels tall, with a 1 pixel thick border around them). In lower resolutions (when the RenderTexture is resized) the health bar bleeds over to the border, and the border becomes inconsistent: Random sides of it disappear (as they bleed/blur into neighbouring pixels) and so the health bar becomes quite ugly. Is there a way to keep 1-pixel thick lines consistent when the rendertexture is resized?

fallahn

  • Hero Member
  • *****
  • Posts: 502
  • Buns.
    • View Profile
    • Trederia
Re: Accommodating different resolutions in 2D games
« Reply #1 on: October 07, 2018, 10:10:04 pm »
This is usually achieved with sf::View. Fix the view to the world size you want to draw (for example 1080p or whatever your assets are designed for) then set the view properties to map it to your window accordingly, including aspect ratio - there's an example on the wiki here. Using this method you can also render UI elements such as health bars separately, via their own view, to maintain things such as pixel sizes independently from the game rendering.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: Accommodating different resolutions in 2D games
« Reply #2 on: October 08, 2018, 08:20:17 am »
I have tried using a different view for the health bars using mapCoordsToPixel to position them. There's too much flickering when I move the camera (camera = game world view). I use a "hold right mouse button to drag the screen" method and the 1-pixel thick health bar borders just disappear at random positions and the positioning update is not as smooth as I want it to be.