Page 1 of 1

Scaling

Posted: Thu Apr 26, 2012 7:58 pm
by AlgidPlasma
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?

Re: Scaling

Posted: Thu Apr 26, 2012 8:37 pm
by bartbes
Using love.graphics.scale, perhaps?

Re: Scaling

Posted: Thu Apr 26, 2012 9:11 pm
by sanjiv
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.

Re: Scaling

Posted: Thu Apr 26, 2012 9:18 pm
by AlgidPlasma
I didnt know that existed :P , but now everything is fuzzy

Re: Scaling

Posted: Thu Apr 26, 2012 11:25 pm
by Kingdaro
put the command

Code: Select all

love.graphics.setDefaultImageFilter('linear','nearest')
in love.load before all of your image loadings.

and also make sure you're using 0.8 :P

Re: Scaling

Posted: Fri Apr 27, 2012 8:59 pm
by AlgidPlasma
Do fonts scale? :?

Re: Scaling

Posted: Sun Apr 29, 2012 12:58 pm
by felix24
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:

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
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:

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
then in your draw function have:

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
hope this helps.
good luck ^^

p.s. yes fonts do scale

Re: Scaling

Posted: Sun Apr 29, 2012 5:05 pm
by Larsii30
Awesome. Thanks Felix. :)