diff options
Diffstat (limited to 'Camera.lua')
| -rw-r--r-- | Camera.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Camera.lua b/Camera.lua new file mode 100644 index 0000000..8a12fa8 --- /dev/null +++ b/Camera.lua @@ -0,0 +1,24 @@ +local game = require 'game' + +local Camera = game.Object:extend() + +function Camera:use() + local x, y = unpack(self.pos) + local scale = 1 / self.scale + local transform = love.math.newTransform( + -x + 1920 / 2, -y + 1080 / 2, -self.rot, scale, scale) + love.graphics.applyTransform(transform) +end + +function Camera:follow(obj) + self.following = obj +end + +function Camera:update(dt) + if self.following then + self.pos[1] = self.following.pos[1] + self.pos[2] = self.following.pos[2] + end +end + +return Camera |
