-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.lua
More file actions
36 lines (29 loc) · 779 Bytes
/
camera.lua
File metadata and controls
36 lines (29 loc) · 779 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
local camera = {}
local mt = {__index = camera}
function camera.new(x,y,extents)
local self = {
x = x or 0,
y = y or 0,
size = extents,
zoom = 1
}
setmetatable(self, mt)
return self
end
function camera:translate(dx,dy)
self.x, self.y = self.x+dx, self.y+dy
end
function camera:toWorld(px, py)
--return (self.x-px)/self.zoom, (self.y-py)/self.zoom
--return (px-self.x)/self.zoom, (py-self.y)/self.zoom
--return (self.x+px)/self.zoom, (self.y+py)/self.zoom
return self.x + px/self.zoom, self.y + py/self.zoom
end
function camera:draw(drawCall)
love.graphics.push()
love.graphics.scale(self.zoom)
love.graphics.translate(-self.x, -self.y)
drawCall()
love.graphics.pop()
end
return camera