modules/world: simplify limitView() by using utils.math.between()

This commit is contained in:
Kazhnuz 2019-05-02 16:19:28 +02:00
parent 8073951822
commit f1edd118ec

View file

@ -236,25 +236,17 @@ function CameraSystem:getViewScale(id)
end end
function CameraSystem:limitView(id) function CameraSystem:limitView(id)
local viewx, viewy, vieww, viewh = self:getViewCoordinate(id) local viewx, viewy, vieww, viewh = self:getViewCoordinate(id)
local worldw, worldh = self.world:getDimensions()
local posx = self.views.list[id].pos.x
local posy = self.views.list[id].pos.y
local minx = self.views.width / 2
local miny = self.views.height / 2
local maxx = worldw - minx
local maxy = worldh - miny
if (viewx < 0) then self.views.list[id].pos.x = utils.math.between(posx, minx, maxx)
self.views.list[id].pos.x = (self.views.width / 2) self.views.list[id].pos.y = utils.math.between(posy, miny, maxy)
end
if (viewy < 0) then
self.views.list[id].pos.y = (self.views.height / 2)
end
local worldw, worldh = self.world:getDimensions()
if ((viewx + vieww) > worldw) then
self.views.list[id].pos.x = worldw - (self.views.width / 2)
end
if ((viewy + viewh) > worldh) then
self.views.list[id].pos.y = worldh - (self.views.height / 2)
end
self:computeCamPosition(id) self:computeCamPosition(id)
end end