image scaling on mouse wheel up/down

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
champ99
Prole
Posts: 1
Joined: Sun Feb 13, 2011 10:18 pm

image scaling on mouse wheel up/down

Post 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
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: image scaling on mouse wheel up/down

Post 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
Attachments
scale.love
0.7.0
(3.45 KiB) Downloaded 260 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: image scaling on mouse wheel up/down

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

Who is online

Users browsing this forum: No registered users and 3 guests