Page 1 of 1

Resizing images

Posted: Sat Jan 16, 2016 3:15 pm
by CalebAnder
Sorry I know this is a noob question ^^ but how do I resize an image. I know how to insert an image but the problem is I don't know how to resize it. Thanks. :awesome:

Re: Resizing images

Posted: Sat Jan 16, 2016 3:40 pm
by s-ol
There's multiple ways, you can use graphics transforms like love.graphics.scale (probably alongside lg.push/pop) or you can use the scale parameters (sx/sy) of the love.graphics.draw, just look at the wiki.

Re: Resizing images

Posted: Sat Jan 16, 2016 4:37 pm
by CalebAnder
Thanks again! So if I was to add a plane to my game I could do this to scale it?

Code: Select all

plane = love.graphics.newImage("plane.png")
love.graphics.scale(0.5, 0.5)

Re: Resizing images

Posted: Sat Jan 16, 2016 4:52 pm
by s-ol
No. Please read the wiki page. There's a perfect example on the bottom even. Also the second method is probably more useful for you anyway, and also documented nicely on the wiki.

Re: Resizing images

Posted: Sat Jan 16, 2016 6:37 pm
by CalebAnder
Ok, I read the wiki page and I tried for an hour to scale the image but I have not had success. I am a huge noob to this so I really don't know how to do it. Please tell me how to scale an image. The wiki tells me how to scale text. I tried with an image but it didn't work. :cry:

Re: Resizing images

Posted: Sat Jan 16, 2016 8:16 pm
by s-ol
love.graphics.scale applies to images, text and graphics primitives alike, as the wiki page says aswell:
someone on the wiki wrote: Scales the coordinate system in two dimensions.

After scaling by sx and sy, all coordinates are treated as if they were multiplied by sx and sy. Every result of a drawing operation is also correspondingly scaled, so scaling by (2, 2) for example would mean making everything twice as large in both x- and y-directions.
All you need to do is

Code: Select all

-- somewhere, outside of a callback
plane = love.graphics.newImage("plane.png")

-- somewhere, probably in love.draw
love.graphics.push()
love.graphics.scale(0.5, 0.5)
love.graphics.draw(plane, 200/0.5, 200/0.5) -- '/ 0.5' because scale affects everything, including position obviously
love.graphics.pop() -- so the scale doesn't affect anything else
but, like I said, love.graphics.scale is probably not what you want, as the same can be accomplished much more reasily using just love.draw:

Code: Select all

-- somewhere, outside of a callback
plane = love.graphics.newImage("plane.png")

-- somewhere, probably in love.draw
love.graphics.draw(plane, 200, 200, 0, 0.5, 0.5) -- 0 is for rotation, see the wiki

Re: Resizing images

Posted: Sun Jan 17, 2016 4:28 am
by CalebAnder
Ah, thank you very much! You are the most helpful person on this forum :awesome: