summaryrefslogtreecommitdiff
path: root/client/camera.lua
blob: bc65044ae16a3ddf4ac263a940ec0acb9f74a688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local coords = require"common.coords"

-- in screen units
local screen_width, screen_height = love.graphics.getDimensions()

-- zoom is screen pixels per world unit
local Camera = {}
Camera.__index = Camera
function Camera.make(pos,zoom)
	pos = pos or coords.Pos.make(0,0)
	zoom = zoom or 30
	return setmetatable({pos=pos,zoom=zoom},Camera)
end
function Camera.apply_trans(self)
	love.graphics.origin()
	-- centre (0,0) in the middle of the screen
	love.graphics.translate(screen_width/2,screen_height/2)
	-- apply camera transformations

	love.graphics.scale(self.zoom)
	love.graphics.translate(-self.pos.x,-self.pos.y)
end


return {Camera=Camera}