Page 1 of 1

Is it possible to set the size of an image?

Posted: Sun Sep 14, 2014 3:12 am
by ForeverDevv
I want to create an image and edit it's size (I don't want to use scale factor, I want to set it to a certain size in pixels)

Is this possible?

Re: Is it possible to set the size of an image?

Posted: Sun Sep 14, 2014 3:37 am
by Ortimh
I think it impossible to change the size of an image within LÖVE. But using scale will do like you want to:

Code: Select all

function setImageSize(image, x, y)
	return x / image:getWidth(), y / image:getHeight()
end
Example, if your image dimensions is 64 x 64 pixels then you want to resize it to 32 x 32 pixels:

Code: Select all

local image = love.graphics.newImage("image.png")

love.graphics.draw(image, 0, 0, 0, setImageSize(image, 32, 32))
setImageSize function returns 0.5 for both scale X and Y.

Re: Is it possible to set the size of an image?

Posted: Sun Sep 14, 2014 4:06 am
by ForeverDevv
Ah, it worked.

Thank you very much!