From 9ea2d2ca40e3e2dc4556d243ba11c010cf9fd73a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 26 Jul 2019 11:43:54 +0200 Subject: [PATCH] feat(world): add a wrapper for maps new "getBox()" function --- gamecore/modules/world/baseworld.lua | 9 +++++++++ gamecore/modules/world/camera/init.lua | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index c0c29a9..2ad0dce 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -289,6 +289,15 @@ function BaseWorld:loadMapObjects() end end +function BaseWorld:getBox() + if (self.map ~= nil) then + return self.map:getBox() + else + local w, h = core.screen:getDimensions() + return 0, 0, w, h + end +end + function BaseWorld:getDimensions() if (self.map ~= nil) then return self.map:getDimensions() diff --git a/gamecore/modules/world/camera/init.lua b/gamecore/modules/world/camera/init.lua index e3d292f..7640d02 100644 --- a/gamecore/modules/world/camera/init.lua +++ b/gamecore/modules/world/camera/init.lua @@ -268,12 +268,12 @@ function CameraSystem:getViewScale(id) end function CameraSystem:limitView(id) - local viewx, viewy, vieww, viewh = self:getViewCoordinate(id) - local worldw, worldh = self.world:getDimensions() + local viewx, viewy, vieww, viewh = self:getViewCoordinate(id) + local worldx, worldy, worldw, worldh = self.world:getBox() local posx = self.views.list[id].x local posy = self.views.list[id].y - local minx = self.views.width / 2 - local miny = self.views.height / 2 + local minx = worldx + self.views.width / 2 + local miny = worldy + self.views.height / 2 local maxx = worldw - minx local maxy = worldh - miny