diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 1636854..348ae0a 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -431,13 +431,10 @@ function BaseWorld:draw(dt) self:drawActors() else for i=1, camNumber do - self.cameras:setScissor(i) self.cameras:attachView(i) self:drawMap(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/init.lua b/gamecore/modules/world/camera/init.lua index b582b04..74175c0 100644 --- a/gamecore/modules/world/camera/init.lua +++ b/gamecore/modules/world/camera/init.lua @@ -149,10 +149,17 @@ function CameraSystem:addView(x, y, target) table.insert(self.views.list, view) self.views.width, self.views.height = self:getViewsDimensions() + self:regenerateCanvases() self:recalculateViewsPositions() end end +function CameraSystem:regenerateCanvases() + for i, view in ipairs(self.views.list) do + view.canvas = love.graphics.newCanvas(self.views.width, self.views.height) + end +end + function CameraSystem:getView(id) return self.views.list[id] end @@ -186,34 +193,45 @@ end function CameraSystem:attachView(id) if (id ~= nil) then - local cam = self:getViewCam(id) + local view = self:getView(id) + + self.current_canvas = love.graphics.getCanvas() + love.graphics.setCanvas(view.canvas) + love.graphics.clear() if id ~= nil then -- Du à la manière dont fonctionne STI, on est obligé de récupérer les info -- de position de camera pour afficher la carte par rapport à ces infos - tx, ty = self:getInternalCamCoordinate(id) - tx, ty = core.screen:getScreenCoordinate(tx, ty) - scale = self:getViewScale(id) or 2 - local vx, vy = self:getOnScreenViewRelativePosition(id) - tx = math.floor(tx - math.abs(vx)) * -1 - ty = math.floor(ty - math.abs(vy)) * -1 + tx, ty = self:getViewCoordinate(id) + scale = self:getViewScale(id) or 1 + tx = math.floor(tx) * -1 * scale + ty = math.floor(ty) * -1 * scale local w, h = core.screen:getDimensions() end - print(tx, ty, scale) - love.graphics.push() love.graphics.origin() love.graphics.translate(math.floor(tx), math.floor(ty)) - love.graphics.scale(scale, scale) + love.graphics.scale(view.cam.scale, view.cam.scale) end end function CameraSystem:detachView(id) if (id ~= nil) then - local cam = self:getViewCam(id) + local view = self:getView(id) + love.graphics.pop() + love.graphics.setCanvas(self.current_canvas) + local tx, ty = self:getOnScreenViewCoordinate(id) + local scale = core.screen:getScale() + love.graphics.push() + love.graphics.origin() + love.graphics.translate(math.floor(tx), math.floor(ty)) + love.graphics.scale(scale, scale) + + love.graphics.draw(view.canvas) + self:drawHUD(id) love.graphics.pop() end end @@ -223,11 +241,13 @@ function CameraSystem:getViewCoordinate(id) local cam = self:getViewCam(id) local viewx, viewy, vieww, viewh - viewx = view.pos.x - ((self.views.width/2) / cam.scale) - viewy = view.pos.y - ((self.views.height/2) / cam.scale) - vieww = self.views.width / cam.scale + vieww = self.views.width / cam.scale viewh = self.views.height / cam.scale + + viewx = view.pos.x - (vieww / 2) + viewy = view.pos.y - (viewh / 2) + return viewx, viewy, vieww, viewh end @@ -285,7 +305,7 @@ end function CameraSystem:getViewScale(id) local cam = self:getViewCam(id) - return cam.scale * core.screen:getScale() + return cam.scale end function CameraSystem:limitView(id) @@ -300,8 +320,6 @@ function CameraSystem:limitView(id) self.views.list[id].pos.x = utils.math.between(posx, minx, maxx) self.views.list[id].pos.y = utils.math.between(posy, miny, maxy) - - self:computeCamPosition(id) end -- UPDATE and MOVE functions @@ -321,7 +339,6 @@ function CameraSystem:moveView(id, x, y) self.views.list[id].pos.x = x self.views.list[id].pos.y = y - self:computeCamPosition(id) self:limitView(id) end @@ -412,14 +429,10 @@ function CameraSystem:drawDebugViewBox(id) end function CameraSystem:drawHUD(id) - local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) local view = self:getView(id) - local string2 = id .. " (" .. viewx .. ":" .. (viewh-viewy) .. ") " + local viewx, viewy, vieww, viewh = self:getOnScreenViewCoordinate(id) - love.graphics.translate(viewx, viewy) view.target:drawHUD(id, vieww, viewh) - - love.graphics.translate(-viewx, -(viewy)) end return CameraSystem