updateBoundaryAnimations
Definition
-- @/lua/ge/extensions/gameplay/crawl/boundary.lua:58
local function updateBoundaryAnimations(dtSim)
if not boundaryObjects then
return
end
local playerPos = nil
if gameplay_crawl_utils and gameplay_crawl_utils.getPlayerPosition then
playerPos = gameplay_crawl_utils.getPlayerPosition()
else
playerPos = core_camera.getPosition()
end
if not playerPos then
return
end
if boundaryQuadtree then
local visibleObjects = {}
local queryX, queryY = playerPos.x, playerPos.y
local queryRadius = visibilityRadius
for objectId in boundaryQuadtree:queryNotNested(
queryX - queryRadius, queryY - queryRadius,
queryX + queryRadius, queryY + queryRadius
) do
local objectInfo = boundaryObjects[objectId]
if objectInfo and playerPos:distance(objectInfo.finalPosition) <= queryRadius then
table.insert(visibleObjects, objectId)
end
end
local visibleLookup = {}
for _, objectId in ipairs(visibleObjects) do
visibleLookup[objectId] = true
end
for objectId, objectInfo in pairs(boundaryObjects) do
local obj = scenetree.findObjectById(objectId)
if obj then
local isCurrentlyVisible = visibleLookup[objectId] or false
local wasVisible = objectInfo.lastVisible
if isCurrentlyVisible and not wasVisible then
objectInfo.animationState = "appearing"
objectInfo.animationTimer = 0
obj.hidden = false
elseif not isCurrentlyVisible and wasVisible then
objectInfo.animationState = "disappearing"
objectInfo.animationTimer = 0
end
if objectInfo.animationState == "appearing" then
objectInfo.animationTimer = objectInfo.animationTimer + dtSim
if objectInfo.animationTimer >= animationDuration then
objectInfo.animationState = "visible"
objectInfo.animationTimer = 0
obj:setScale(vec3(maxScale, maxScale, maxScale))
obj:setField('instanceColor', 0, '1 1 1 1')
else
local scaleT = math.min(objectInfo.animationTimer / scaleUpDuration, 1.0)
local alphaT = math.min(objectInfo.animationTimer / fadeInDuration, 1.0)
local currentScale = lerp(minScale, maxScale, smootherstep(scaleT))
local currentAlpha = lerp(0.0, 1.0, smootherstep(alphaT))
obj:setScale(vec3(currentScale, currentScale, currentScale))
obj:setField('instanceColor', 0, string.format('1 1 1 %.2f', currentAlpha))
end
elseif objectInfo.animationState == "disappearing" then
objectInfo.animationTimer = objectInfo.animationTimer + dtSim
if objectInfo.animationTimer >= fadeOutDuration then
objectInfo.animationState = "hidden"
objectInfo.animationTimer = 0
obj.hidden = true
else
local alphaT = 1.0 - (objectInfo.animationTimer / fadeOutDuration)
local currentAlpha = lerp(0.0, 1.0, smootherstep(alphaT))
obj:setField('instanceColor', 0, string.format('1 1 1 %.2f', currentAlpha))
end
elseif objectInfo.animationState == "visible" then
obj:setScale(vec3(maxScale, maxScale, maxScale))
obj:setField('instanceColor', 0, '1 1 1 1')
end
objectInfo.lastVisible = isCurrentlyVisible
else
boundaryObjects[objectId] = nil
end
end
end
end
Callers
@/lua/ge/extensions/gameplay/crawl/utils.lua
local function updateCrawl(dtSim)
gameplay_crawl_boundary.updateBoundaryAnimations(dtSim)