That is because you are using the offset AND the translation. He mean to remove you love.graphics.translate line and replacing the rectangle drawing with that:
Code: Select all
quad = {}
quad.x = 0
quad.y = 0
quad.sx = 1
quad.sy = 1
quad.r = 0
quad.w = 256
quad.h = 128
quad.ox = quad.w/2
quad.oy = quad.h/2
function love.update(dt)
quad.x, quad.y = love.mouse.getPosition()
end
function love.draw()
love.graphics.scale(quad.sx, quad.sy)
love.graphics.rectangle("fill", quad.x-quad.ox, quad.y-quad.oy, quad.w, quad.h)
end
function love.wheelmoved( x, y )
quad.sx = quad.sx + 0.01*y
quad.sy = quad.sy + 0.01*y
quad.ox = (quad.w*quad.sx)/2
quad.oy = (quad.h*quad.sy)/2
end
But that won't work either, that is because once you scale, all your dimensions are scaled, including mouse coordinates.
In order to fix this you have two options:
Scaling your mouse coordinates back to their original size by dividing them by quad.sx and quad.sy
Code: Select all
quad = {}
quad.x = 0
quad.y = 0
quad.sx = 1
quad.sy = 1
quad.r = 0
quad.w = 256
quad.h = 128
quad.ox = quad.w/2
quad.oy = quad.h/2
function love.update(dt)
quad.x, quad.y = love.mouse.getPosition()
end
function love.draw()
love.graphics.scale(quad.sx, quad.sy)
love.graphics.rectangle("fill", (quad.x/quad.sx)-quad.ox, (quad.y/quad.sy)-quad.oy, quad.w, quad.h)
end
function love.wheelmoved( x, y )
quad.sx = quad.sx + 0.01*y
quad.sy = quad.sy + 0.01*y
quad.ox = (quad.w*quad.sx)/2
quad.oy = (quad.h*quad.sy)/2
end
Or translating to mouse coordinates first, scaling and then drawing the rectangle with it's offset
Code: Select all
quad = {}
quad.x = 0
quad.y = 0
quad.sx = 1
quad.sy = 1
quad.r = 0
quad.w = 256
quad.h = 128
quad.ox = quad.w/2
quad.oy = quad.h/2
function love.update(dt)
quad.x, quad.y = love.mouse.getPosition()
end
function love.draw()
love.graphics.translate(quad.x,quad.y)
love.graphics.scale(quad.sx, quad.sy)
love.graphics.rectangle("fill", -quad.ox, -quad.oy, quad.w, quad.h)
end
function love.wheelmoved( x, y )
quad.sx = quad.sx + 0.01*y
quad.sy = quad.sy + 0.01*y
quad.ox = (quad.w*quad.sx)/2
quad.oy = (quad.h*quad.sy)/2
end
This one is really similar to what you had and is really simpler