module/world: make sure that the view doesn't go outside the world
This commit is contained in:
parent
1c167ba566
commit
a2d38a1ef4
1 changed files with 25 additions and 0 deletions
|
@ -235,6 +235,30 @@ function CameraSystem:getViewScale(id)
|
||||||
return cam.scale
|
return cam.scale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CameraSystem:limitView(id)
|
||||||
|
local viewx, viewy, vieww, viewh = self:getViewCoordinate(id)
|
||||||
|
|
||||||
|
if (viewx < 0) then
|
||||||
|
self.views.list[id].pos.x = (self.views.width / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (viewy < 0) then
|
||||||
|
self.views.list[id].pos.y = (self.views.height / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local worldw, worldh = self.world:getDimensions()
|
||||||
|
|
||||||
|
if ((viewx + vieww) > worldw) then
|
||||||
|
self.views.list[id].pos.x = worldw - (self.views.width / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ((viewy + viewh) > worldh) then
|
||||||
|
self.views.list[id].pos.y = worldh - (self.views.height / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
self:computeCamPosition(id)
|
||||||
|
end
|
||||||
|
|
||||||
-- UPDATE and MOVE functions
|
-- UPDATE and MOVE functions
|
||||||
-- Move and update the camera system
|
-- Move and update the camera system
|
||||||
|
|
||||||
|
@ -249,6 +273,7 @@ function CameraSystem:moveView(id, x, y)
|
||||||
self.views.list[id].pos.y = y
|
self.views.list[id].pos.y = y
|
||||||
|
|
||||||
self:computeCamPosition(id)
|
self:computeCamPosition(id)
|
||||||
|
self:limitView(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CameraSystem:computeCamPosition(id)
|
function CameraSystem:computeCamPosition(id)
|
||||||
|
|
Loading…
Reference in a new issue