blob: 5a9c87baa78fc25f8b0d6c4b7f117c49ea0449d2 (
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
26
27
28
29
30
31
|
local component = require 'component'
local Transform = require 'Transform'
-- a view of the world
local Camera = component({Transform})
function Camera:use()
self.obj.world.camera = self
end
function Camera:transform()
local trans = self.obj:get(Transform):love()
local cam_trans = love.math.newTransform(1920 / 2, 1080 / 2)
love.graphics.applyTransform(cam_trans * trans:inverse())
end
function Camera:follow(obj)
assert(obj:get(Transform))
self.i.following = obj
end
function Camera:update(dt)
if self.i.following then
local this = self.obj:get(Transform)
local follow = self.i.following:get(Transform)
this.i.pos[1] = follow.i.pos[1]
this.i.pos[2] = follow.i.pos[2]
end
end
return Camera
|