From 940cb1b41f929351c2572159f8aa80bb873f7836 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 1 Jul 2019 14:15:10 +0200 Subject: [PATCH] improvement(camera): use the shape system to control the camera. --- gamecore/modules/world/camera.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index 33fe4aa..8284b44 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -357,18 +357,19 @@ function CameraSystem:followAllActors(id) if (#self.targets > 0) then local minX, minY, maxX, maxY for i, target in ipairs(self.targets) do - local xx, yy = target:getViewCenter() + local x, y, w, h = target:getShape() + local x2, y2 = x + w, y + h -- If start by initializing the value at the first found value - if (minX == nil) then minX = xx - (target.w/2) end - if (maxX == nil) then maxX = xx + (target.w/2) end - if (minY == nil) then minY = yy - (target.h/2) end - if (maxY == nil) then maxY = yy + (target.h/2) end + if (minX == nil) then minX = x end + if (maxX == nil) then maxX = x2 end + if (minY == nil) then minY = y end + if (maxY == nil) then maxY = y2 end - minX = math.min(minX, xx - (target.w/2)) - maxX = math.max(maxX, xx + (target.w/2)) - minY = math.min(minY, yy - (target.h/2)) - maxY = math.max(maxY, yy + (target.h/2)) + minX = math.min(minX, x) + maxX = math.max(maxX, x2) + minY = math.min(minY, y) + maxY = math.max(maxY, y2) end -- Add padding