Page 1 of 1

Scaling a single image

Posted: Wed May 02, 2012 7:00 pm
by Charlie
Hi everyone. I am just starting with LOVE (not programming) and am just tinkering with some basic things right now.
Is the love.graphics.scale() the appropriate way to scale a single image, using push and pop with it?
This doesn't seem too practical if so because it offsets the location on screen of the image.
This command seems more geared towards total screen zooming.

Below is a small script i made to test scaling.
One block scales and one doesn't. But the scaling block moves across the screen while scaling before ending up at it's correct x and y position.
Is this the only way of scaling a single image? This would require creating offsets of positions for images which could become pretty messy to deal with.
I hope I'm just missing something lol.

Code: Select all

function love.load()
	block = love.graphics.newImage("/images/block.png")
	x = 300
	y = 300
	scale = 0.5
end

function love.update(dt)
	if scale < 1 then 
		scale = scale + 0.01
	end
end

function love.draw()
	love.graphics.push()
	love.graphics.scale(scale,scale)
	
	love.graphics.draw(block,x,y)
	
	love.graphics.pop()
	love.graphics.draw(block,30,30)
end
Thanks in advance!

Re: Scaling a single image

Posted: Wed May 02, 2012 9:23 pm
by bartbes
I see this come up a lot with new users, why, though? It's all on the wiki.

Short answer: love.graphics.draw has scale arguments!

Re: Scaling a single image

Posted: Wed May 02, 2012 10:43 pm
by Charlie
lol thanks. I got it figured out before this post got approved. Yes it's on the wiki..but it's impossible to see everything right away when you know nothing about the language. Thanks again!