diff --git a/gamecore/modules/world/camera/init.lua b/gamecore/modules/world/camera/init.lua index a6f9576..add1031 100644 --- a/gamecore/modules/world/camera/init.lua +++ b/gamecore/modules/world/camera/init.lua @@ -164,8 +164,8 @@ function CameraSystem:attachView(id) -- de position de camera pour afficher la carte par rapport à ces infos tx, ty = self:getViewCoordinate(id) scale = self:getViewScale(id) or 1 - tx = math.floor(tx) * -1 * scale - ty = math.floor(ty) * -1 * scale + tx = math.floor(tx) * -1 + ty = math.floor(ty) * -1 local w, h = core.screen:getDimensions() end @@ -173,25 +173,30 @@ function CameraSystem:attachView(id) love.graphics.push() love.graphics.origin() love.graphics.translate(math.floor(tx), math.floor(ty)) - love.graphics.scale(view.scale, view.scale) end end function CameraSystem:detachView(id) if (id ~= nil) then local view = self:getView(id) + love.graphics.rectangle("fill", view.x-8, view.y-8, 16, 16) love.graphics.pop() love.graphics.setCanvas(self.current_canvas) local tx, ty = self:getOnScreenViewCoordinate(id) - local scale = core.screen:getScale() + local scale = core.screen:getScale() * view.scale + 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) + + local unscale = 1 / view.scale + love.graphics.scale(unscale, unscale) self:drawHUD(id) + love.graphics.pop() end end @@ -247,6 +252,16 @@ function CameraSystem:getOnScreenViewCenter(id) return core.screen:getScreenCoordinate(viewx, viewy) end +function CameraSystem:setViewScale(id, scale) + local view = self:getView(id) + + view.scale = scale + + local _, _, w, h = self:getViewCoordinate(id) + + view.canvas = love.graphics.newCanvas(math.ceil(w), math.ceil(h)) +end + function CameraSystem:getViewScale(id) local view = self:getView(id) @@ -337,7 +352,7 @@ function CameraSystem:followAllActors(id) local scalex = (maxX-minX)/ww local scaley = (maxY-minY)/hh scale = math.max(scale, scalex, scaley) - view.scale = 1/scale + self:setViewScale(id, 1/scale) self.world:resizeMap(ww * 3, hh * 3) end