Math has never been my strong point, and i'm in a pickle figuring this out for a platformer engine i've been making.
The default window size is 1024 x 768, when not fullscreen.
Let's say the user had 1920 x 1080 as their resolution, when toggling into fullscreen (desktop) mode the window will simply have a wider draw distance.
How can i calculate the scaling of a camera dynamically, depending on the resolution so that the on screen drawables are always scaled proportionately to the default windowed resolution?
Some screenshots showing the differences, ideally i would like to get the camera scale adjusted in fullscreen mode to look close enough to the windowed version. So that any screen resolution could be used?
Windowed:
Fullscreen (but unwanted extra draw distance):
[SOLVED] Dynamic camera scaling dependent on resolution?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Dynamic camera scaling dependent on resolution?
Last edited by unixfreak on Sat Apr 08, 2017 5:34 pm, edited 1 time in total.
Re: Dynamic camera scaling dependent on resolution?
Well more fiddling about this seems to work:
Although the width is not perfect, how can i improve that to get the exact horizontal view distance in any resolution?
Code: Select all
local scale = (default_width / (love.graphics.getWidth() * love.graphics.getHeight()) *1000)
camera.scaleX = scale
camera.scaleY = scale
Re: Dynamic camera scaling dependent on resolution?
Here's how I do it. I also usually do letterboxing but that's an extra step I'll just drop for now.
Side thing: if you're making a horizontal platformer, maybe you'd prefer to only ever use scale_x, so that the distance between the player and the edge of the screen is fixed and same deal for a vertically facing game. This way you keep the screen size relevant to the gameplay at the expense of looking weird in edge case resolutions
Side thing: if you're making a horizontal platformer, maybe you'd prefer to only ever use scale_x, so that the distance between the player and the edge of the screen is fixed and same deal for a vertically facing game. This way you keep the screen size relevant to the gameplay at the expense of looking weird in edge case resolutions
Code: Select all
-- target: This is the "intended" resolution, the one where you want the camera scale to be x1
-- screen: The actual resolution, as returned by love.graphics.getDimensions()
local scale_x = screen_w / target_w
local scale_y = screen_h / target_h
local scale = math.min(scale_x, scale_y) -- for pixel perfect scaling, floor the result
-- before drawing
love.graphics.scale(scale, scale)
Re: Dynamic camera scaling dependent on resolution?
Thank you so much, and for explaining it too, that scales perfectly.alloyed wrote: ↑Sat Apr 08, 2017 5:22 pm Here's how I do it. I also usually do letterboxing but that's an extra step I'll just drop for now.
Side thing: if you're making a horizontal platformer, maybe you'd prefer to only ever use scale_x, so that the distance between the player and the edge of the screen is fixed and same deal for a vertically facing game. This way you keep the screen size relevant to the gameplay at the expense of looking weird in edge case resolutionsCode: Select all
-- target: This is the "intended" resolution, the one where you want the camera scale to be x1 -- screen: The actual resolution, as returned by love.graphics.getDimensions() local scale_x = screen_w / target_w local scale_y = screen_h / target_h local scale = math.min(scale_x, scale_y) -- for pixel perfect scaling, floor the result -- before drawing love.graphics.scale(scale, scale)
That's really helped, much better than the "hack" i came up with.
Many thanks!
Who is online
Users browsing this forum: Bing [Bot] and 74 guests