Resizing images

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
CalebAnder
Prole
Posts: 16
Joined: Fri Jan 15, 2016 6:33 pm

Resizing images

Post 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:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Resizing images

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
CalebAnder
Prole
Posts: 16
Joined: Fri Jan 15, 2016 6:33 pm

Re: Resizing images

Post 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)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Resizing images

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
CalebAnder
Prole
Posts: 16
Joined: Fri Jan 15, 2016 6:33 pm

Re: Resizing images

Post 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:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Resizing images

Post 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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
CalebAnder
Prole
Posts: 16
Joined: Fri Jan 15, 2016 6:33 pm

Re: Resizing images

Post by CalebAnder »

Ah, thank you very much! You are the most helpful person on this forum :awesome:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests