From 208c523248857fc0929ab78e308c5a424ccbb380 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 13 Jul 2019 00:29:43 +0200 Subject: [PATCH] fix(camera): fix map not being clipped in split mode Fixes #29 --- gamecore/modules/world/baseworld.lua | 2 ++ gamecore/modules/world/camera.lua | 35 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 52a5487..35f7529 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -431,11 +431,13 @@ function BaseWorld:draw(dt) self:drawActors() else for i=1, camNumber do + self.cameras:setScissor(i) self:drawMap(i) self.cameras:attachView(i) self:drawActors(i) self.cameras:detachView(i) self.cameras:drawHUD(i) + self.cameras:resetScissor( ) end end end diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index 8284b44..464bb07 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -194,21 +194,32 @@ function CameraSystem:getViewCam(id) return view.cam end +function CameraSystem:setScissor(id) + local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) + + if (self:getViewNumber() > 2) or (self:getViewNumber() == 2 and SPLITSCREEN_ISVERTICAL) then + -- FIXME: it's an ugly workaround that need to be fixed. For an unkown + -- reason, the scissoring is wrong in and only in this function and only + -- when we have vertical split. Thus, we need to substract viewy to viewy + viewy = viewh - viewy + end + + if (self.mode == "split") then + love.graphics.setScissor(viewx, viewy, vieww, viewh) + end +end + +function CameraSystem:resetScissor( ) + if (self.mode == "split") then + love.graphics.setScissor( ) + end +end + function CameraSystem:attachView(id) if (id ~= nil) then local cam = self:getViewCam(id) - local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) cam:attach() - - if (self:getViewNumber() > 2) or (self:getViewNumber() == 2 and SPLITSCREEN_ISVERTICAL) then - -- FIXME: it's an ugly workaround that need to be fixed. For an unkown - -- reason, the scissoring is wrong in and only in this function and only - -- when we have vertical split. Thus, we need to substract viewy to viewy - viewy = viewh - viewy - end - - love.graphics.setScissor(viewx, viewy, vieww, viewh) end end @@ -216,7 +227,6 @@ function CameraSystem:detachView(id) if (id ~= nil) then local cam = self:getViewCam(id) - love.graphics.setScissor( ) cam:detach() end end @@ -417,13 +427,10 @@ function CameraSystem:drawHUD(id) local view = self:getView(id) local string2 = id .. " (" .. viewx .. ":" .. (viewh-viewy) .. ") " - - love.graphics.setScissor(viewx, viewy, vieww, viewh) love.graphics.translate(viewx, viewy) view.target:drawHUD(id, vieww, viewh) love.graphics.translate(-viewx, -(viewy)) - love.graphics.setScissor( ) end return CameraSystem