From 077b1151f1568cc5e81a5da6a6182d47c06c2c21 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Sep 2019 21:04:35 +0200 Subject: [PATCH] feat(world/cam): add a way to lock the camera --- gamecore/modules/world/camera/init.lua | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gamecore/modules/world/camera/init.lua b/gamecore/modules/world/camera/init.lua index 49487ff..9a136c4 100644 --- a/gamecore/modules/world/camera/init.lua +++ b/gamecore/modules/world/camera/init.lua @@ -42,6 +42,9 @@ function CameraSystem:new(world) self.verticalSplit = SPLITSCREEN_ISVERTICAL self.targets = {} + self.xLocked = nil + self.yLocked = nil + self:initViews() end @@ -103,6 +106,23 @@ function CameraSystem:getViewPositions(id) end +function CameraSystem:lockX(x) + self.xLocked = x +end + +function CameraSystem:unlockX() + self.xLocked = nil +end + +function CameraSystem:lockY(y) + self.yLocked = y +end + +function CameraSystem:unlockY() + self.yLocked = nil +end + + -- WRAPPER and UTILS -- Access data from the views @@ -279,6 +299,14 @@ function CameraSystem:limitView(id) self.views.list[id].x = utils.math.between(posx, minx, maxx) self.views.list[id].y = utils.math.between(posy, miny, maxy) + + if (self.xLocked ~= nil) then + self.views.list[id].x = self.xLocked + end + + if (self.yLocked ~= nil) then + self.views.list[id].y = self.yLocked + end end -- UPDATE and MOVE functions