diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index 4adb8cb..88eb2ae 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -235,6 +235,30 @@ function CameraSystem:getViewScale(id) return cam.scale 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 -- Move and update the camera system @@ -249,6 +273,7 @@ function CameraSystem:moveView(id, x, y) self.views.list[id].pos.y = y self:computeCamPosition(id) + self:limitView(id) end function CameraSystem:computeCamPosition(id)