Page 1 of 1

image scaling on mouse wheel up/down

Posted: Sun Feb 13, 2011 10:24 pm
by champ99
i have been trying to use the mouse wheel up to zoom in and mouse wheel down to zoom out of an image..i have been trying to find a code for that and been trying to write one myself but cant do it..anyone can help me plz..

function love.load()
hamster = love.graphics.newImage("world_map.gif")
end

function love.update(dt)
if love.mouse.isDown("wu") then
love.graphics.scale(hamster, 45, 65)
end
end

function love.draw()
love.graphics.print( text, 330, 300 )
love.graphics.draw(hamster, x, y)
if love.mouse.isDown("wu") then
love.graphics.scale(hamster, 45, 65)
end
end
end

thank you in anticipation
regards

Re: image scaling on mouse wheel up/down

Posted: Sun Feb 13, 2011 10:42 pm
by TechnoCat
You are using scale wrong: http://love2d.org/wiki/love.graphics.scale

Code: Select all

function love.load()
  image = love.graphics.newImage("body.png")
  scale = 1
end

function love.update(dt)
  --do nothing
end

function love.draw()
  love.graphics.scale(scale,scale)
    love.graphics.draw(image,0,0)
end

function love.mousepressed(x,y, button)
  if button == "wu" then
    scale = scale + scale / 4
  elseif button == "wd" then
    scale = scale - scale / 4
  end
end

Re: image scaling on mouse wheel up/down

Posted: Wed Feb 16, 2011 9:02 pm
by Kadoba
This is the way I do it

Code: Select all

function love.mousepressed( x, y, mb )
	if mb == "wu" then
		scale = scale - 0.2
	end

	if mb == "wd" then
		scale = scale + 0.2
	end
end

function love.draw()
	love.graphics.scale(scale)
end