feat(camera): add a way to lock the camera position

This commit is contained in:
Kazhnuz 2019-08-02 13:52:50 +02:00
parent 28edc63080
commit 5968f82d52

View file

@ -42,6 +42,9 @@ function CameraSystem:new(world)
self.verticalSplit = SPLITSCREEN_ISVERTICAL self.verticalSplit = SPLITSCREEN_ISVERTICAL
self.targets = {} self.targets = {}
self.xLocked = nil
self.yLocked = nil
self:initViews() self:initViews()
end end
@ -103,6 +106,23 @@ function CameraSystem:getViewPositions(id)
end 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 -- WRAPPER and UTILS
-- Access data from the views -- 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].x = utils.math.between(posx, minx, maxx)
self.views.list[id].y = utils.math.between(posy, miny, maxy) 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 end
-- UPDATE and MOVE functions -- UPDATE and MOVE functions