fix(camera): fix map not being clipped in split mode

Fixes #29
This commit is contained in:
Kazhnuz 2019-07-13 00:29:43 +02:00
parent fafaa3fe49
commit 208c523248
2 changed files with 23 additions and 14 deletions

View file

@ -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

View file

@ -194,12 +194,8 @@ function CameraSystem:getViewCam(id)
return view.cam
end
function CameraSystem:attachView(id)
if (id ~= nil) then
local cam = self:getViewCam(id)
function CameraSystem:setScissor(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
@ -208,15 +204,29 @@ function CameraSystem:attachView(id)
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)
cam:attach()
end
end
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