Scaling
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 19
- Joined: Mon Dec 19, 2011 11:17 pm
Scaling
Hey, I want to make a game with a completely re sizable window that supports any 16:9 resolution however I don't know how to scale the images and math to support it. Originally i would work with really small floating point numbers and multiply everything by a global SCALE variable but this has become tedious and leads me to think that all the math could potentially slow down performance. Any Ideas on how to ideally solve my problem?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Scaling
Using love.graphics.scale, perhaps?
Re: Scaling
global SCALE variable + love.graphics.scale = WIN. That's what I did and it worked well. I changed the global scale variable using keyboard inputs as needed.
-
- Prole
- Posts: 19
- Joined: Mon Dec 19, 2011 11:17 pm
Re: Scaling
I didnt know that existed , but now everything is fuzzy
Re: Scaling
put the commandin love.load before all of your image loadings.
and also make sure you're using 0.8
Code: Select all
love.graphics.setDefaultImageFilter('linear','nearest')
and also make sure you're using 0.8
Re: Scaling
here's one way to do it. pick a default screen size. eg: 1280x720. this will be your normal window size with no scaling. so, seeing as you want a 16:9 aspect ratio across the board, to get the scaling factor for windows that are smaller or larger than your default, divide the current height of the window (love.graphics.getHeight()) by 720. this will leave you with the amount to scale by.
eg:
this will scale the graphics accordingly, but in order for the screen to look the same as before, we need to translate (move) the graphics also. this is because when you scale, it "zooms in/out", keeping the top left hand corner (0,0) locked (i.e, if you scale down, everything moves towards 0,0. if you scale up everything moves away from 0,0), making the content shown on the screen look different. so to offset this effect, we need to find how much we need to translate the graphics along the y axis.
eg:
then in your draw function have:
hope this helps.
good luck
p.s. yes fonts do scale
eg:
Code: Select all
scaleAmount = love.graphics.getHeight()/720
Code: Select all
function love.draw()
love.graphics.push()
love.graphics.scale(scaleAmount,scaleAmount)
--your code
love.graphics.pop()
end
eg:
Code: Select all
if scaleAmount > 1 then--scale up
int,fract = math.modf(scaleAmount)
movey = currentHeight * fract
elseif scaleAmount < 1 then-scale down
movey = currentHeight * (1-scaleAmount)
end
Code: Select all
function love.draw()
if scaleAmount > 1 then
love.graphics.push()
love.graphics.translate(0 , -movey )
love.graphics.scale(scaleAmount,scaleAmount)
elseif scaleAmount < 1 then
love.graphics.push()
love.graphics.translate(0 , movey )
love.graphics.scale(scaleAmount,scaleAmount)
end
--your code
if scaleAmount ~= 0 then
love.graphics.pop()
end
end
good luck
p.s. yes fonts do scale
Last edited by felix24 on Sun Apr 29, 2012 8:15 pm, edited 2 times in total.
Re: Scaling
Awesome. Thanks Felix.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 2 guests