fix(camera): fix tearing and heavy pixelisation in zoom mode

Currently, the canvas was created at render size and elements where 
resized inside. Work a bit differenlty, by creating a canvas that have 
the view "true" size (meaning the scaled size), and draw everything at 
1:1 size inside. Then, when drawing the view canvas, resize the whole 
canvas at the multiplication of both scaling.
This commit is contained in:
Kazhnuz 2019-07-15 10:04:06 +02:00
parent f2cabff81c
commit 2f7d313ab9
1 changed files with 20 additions and 5 deletions

View File

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