Scaling

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
AlgidPlasma
Prole
Posts: 19
Joined: Mon Dec 19, 2011 11:17 pm

Scaling

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Scaling

Post by bartbes »

Using love.graphics.scale, perhaps?
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Re: Scaling

Post 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.
AlgidPlasma
Prole
Posts: 19
Joined: Mon Dec 19, 2011 11:17 pm

Re: Scaling

Post by AlgidPlasma »

I didnt know that existed :P , but now everything is fuzzy
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Scaling

Post 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
AlgidPlasma
Prole
Posts: 19
Joined: Mon Dec 19, 2011 11:17 pm

Re: Scaling

Post by AlgidPlasma »

Do fonts scale? :?
User avatar
felix24
Party member
Posts: 163
Joined: Tue Jul 26, 2011 4:51 pm
Contact:

Re: Scaling

Post 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
Last edited by felix24 on Sun Apr 29, 2012 8:15 pm, edited 2 times in total.
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: Scaling

Post by Larsii30 »

Awesome. Thanks Felix. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 2 guests