modules/world: simplify limitView() by using utils.math.between()
This commit is contained in:
parent
8073951822
commit
f1edd118ec
1 changed files with 10 additions and 18 deletions
|
@ -237,24 +237,16 @@ 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)
|
||||||
|
|
||||||
if (viewx < 0) then
|
|
||||||
self.views.list[id].pos.x = (self.views.width / 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if (viewy < 0) then
|
|
||||||
self.views.list[id].pos.y = (self.views.height / 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local worldw, worldh = self.world:getDimensions()
|
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 + vieww) > worldw) then
|
self.views.list[id].pos.x = utils.math.between(posx, minx, maxx)
|
||||||
self.views.list[id].pos.x = worldw - (self.views.width / 2)
|
self.views.list[id].pos.y = utils.math.between(posy, miny, maxy)
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue