-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.lua
57 lines (46 loc) · 1.25 KB
/
camera.lua
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
camera = {}
camera.x = 0
camera.y = 0
camera.scaleX = 1
camera.scaleY = 1
camera.rotation = 0
camera.rotationCenterX = 0
camera.rotationCenterY = 0
function camera:set()
love.graphics.push()
love.graphics.translate(-self.x, -self.y)
love.graphics.translate(self.rotationCenterX, self.rotationCenterY)
love.graphics.rotate(-self.rotation)
love.graphics.translate(-self.rotationCenterX, -self.rotationCenterY)
love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
end
function camera:unset()
love.graphics.pop()
end
function camera:move(dx, dy)
self.x = self.x + (dx or 0)
self.y = self.y + (dy or 0)
end
function camera:rotate(dr)
self.rotation = self.rotation + dr
end
function camera:setRotation(dr)
self.rotation = dr or self.rotation
end
function camera:setRotationCenter(centerX, centerY)
self.rotationCenterX = centerX or self.rotationCenterX
self.rotationCenterY = centerY or self.rotationCenterY
end
function camera:scale(sx, sy)
sx = sx or 1
self.scaleX = self.scaleX * sx
self.scaleY = self.scaleY * (sy or sx)
end
function camera:setPosition(x, y)
self.x = x or self.x
self.y = y or self.y
end
function camera:setScale(sx, sy)
self.scaleX = sx or self.scaleX
self.scaleY = sy or self.scaleY
end