feat(world/cam): add a way to lock the camera

This commit is contained in:
Kazhnuz 2019-09-07 21:04:35 +02:00
parent 0fecc3a431
commit 077b1151f1

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