I am trying to make a camera that can zoom in and out; but, when zooming in it zooms towards the mouse, so that you can pan the world map and zoom into the place you want to look at easily. Unfortunately, I can't quite seem to grasp how this would work. I finally was able to get the out to zoom in the center point, but if I attempt to adjust this I just the camera to spasm all over the place.
Code: Select all
function CameraSystem:set()
local camera = self:findComponent('Camera')
local w,h = love.graphics.getWidth(), love.graphics.getHeight()
local dx, dy = w/2 * (camera.Scale-1), h/2 * (camera.Scale-1)
love.graphics.print("Camera X: "..camera.Pos.X.." Y: "..camera.Pos.Y, 10, 25)
love.graphics.print("Camera Scale: "..camera.Scale, 10, 40)
love.graphics.setScissor(0, 0, w, h)
--Camera draw logic
love.graphics.push()
--love.graphics.translate(camera.Offset.X, camera.Offset.Y) --This offset is the mouse position when zooming in, otherwise 0,0 when added it spasms
love.graphics.scale(1 / camera.Scale)
love.graphics.rotate(-camera.Rotation)
love.graphics.translate(-camera.Pos.X+dx, -camera.Pos.Y+dy)
--Box of zoomed viewport
love.graphics.rectangle("line", camera.Pos.X, camera.Pos.Y, w, h)
end
Thanks for any help!
--EDIT--
Forgot to attach a .love, and had to wait for an approval since I am new here.