Here it is:
Code: Select all
-- CameraMan 1.0, the first thing in Love2D with a appropriate name!
-- Credits:
-- iToast - design
-- Ensayia - Usefull example / suggestions
camera = {}
camera.x = 0
camera.y = 0
function updateCamera(ox, oy, wd, wh)
if ox == nil or oy == nil or wd == nil or wh == nil then
ox = 0
oy = 0
wd = 0
wh = 0
end
camera.x = -ox + (wd / 2)
camera.y = -oy + (wh / 2)
end
function pushCamera()
love.graphics.push()
love.graphics.translate(camera.x, camera.y)
end
function popCamera()
love.graphics.pop()
end
-- example by Ensayia
-- pushCamera()
-- love.graphics.draw(image, x + camera.x, y + camera.y)
--and everything else
-- popCamera()
-- Notes by iToast
-- Player doesn't get drawn between pushCamera() and popCamera()
The main reason for making this is I needed a stupidly simple camera package. This doesn't even support scaling! It's perfect for top down games how ever.
-edit-
Fixed file structure