[lua] Fixed animation layering. Cause of the bug was a few places using pairs instead of manually iterating through all indices from 0 to len. Closes #1574.

This commit is contained in:
badlogic 2020-01-11 15:35:56 +01:00
parent 1855870d37
commit 9b801a993e
2 changed files with 78 additions and 51 deletions

View File

@ -227,7 +227,10 @@ function AnimationState:update (delta)
delta = delta * self.timeScale delta = delta * self.timeScale
local tracks = self.tracks local tracks = self.tracks
local queue = self.queue local queue = self.queue
for i,current in pairs(tracks) do local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then if current then
current.animationLast = current.nextAnimationLast current.animationLast = current.nextAnimationLast
current.trackLast = current.nextTrackLast current.trackLast = current.nextTrackLast
@ -290,6 +293,7 @@ function AnimationState:update (delta)
end end
end end
end end
i = i + 1
end end
queue:drain() queue:drain()
@ -329,7 +333,11 @@ function AnimationState:apply (skeleton)
local queue = self.queue local queue = self.queue
local applied = false local applied = false
for i,current in pairs(tracks) do local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then
if not (current == nil or current.delay > 0) then if not (current == nil or current.delay > 0) then
applied = true applied = true
@ -375,6 +383,8 @@ function AnimationState:apply (skeleton)
current.nextTrackLast = current.trackTime current.nextTrackLast = current.trackTime
end end
end end
i = i + 1
end
queue:drain() queue:drain()
return applied return applied
@ -602,7 +612,9 @@ function AnimationState:clearTracks ()
local tracks = self.tracks local tracks = self.tracks
local oldDrainDisabled = queue.drainDisabled local oldDrainDisabled = queue.drainDisabled
queue.drainDisabled = true; queue.drainDisabled = true;
for i,track in pairs(tracks) do local numTracks = #tracks
local i = 0
while i <= numTracks do
self:clearTrack(i) self:clearTrack(i)
end end
tracks = {} tracks = {}
@ -751,8 +763,13 @@ function AnimationState:setEmptyAnimations (mixDuration)
local queue = self.queue local queue = self.queue
local oldDrainDisabled = queue.drainDisabled local oldDrainDisabled = queue.drainDisabled
queue.drainDisabled = true queue.drainDisabled = true
for i,current in pairs(self.tracks) do local tracks = self.tracks
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then self:setEmptyAnimation(current.trackIndex, mixDuration) end if current then self:setEmptyAnimation(current.trackIndex, mixDuration) end
i = i + 1
end end
queue.drainDisabled = oldDrainDisabled queue.drainDisabled = oldDrainDisabled
queue:drain() queue:drain()
@ -814,7 +831,12 @@ function AnimationState:_animationsChanged ()
self.propertyIDs = {} self.propertyIDs = {}
local highestIndex = -1 local highestIndex = -1
for i, entry in pairs(self.tracks) do local tracks = self.tracks
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then
if i > highestIndex then highestIndex = i end if i > highestIndex then highestIndex = i end
if entry then if entry then
@ -830,6 +852,8 @@ function AnimationState:_animationsChanged ()
until (entry == nil) until (entry == nil)
end end
end end
i = i + 1
end
self.propertyIDs = {} self.propertyIDs = {}
for i = highestIndex, 0, -1 do for i = highestIndex, 0, -1 do

View File

@ -174,10 +174,12 @@ function utils.randomTriangularWith(min, max, mode)
end end
function utils.testBit(value, bit) function utils.testBit(value, bit)
if (value == nil) then return 0 end
return value % (2 * bit) >= bit return value % (2 * bit) >= bit
end end
function utils.setBit(value, bit) function utils.setBit(value, bit)
if (value == nil) then return 0 end
if value % (2 * bit) >= bit then if value % (2 * bit) >= bit then
return value return value
end end
@ -185,6 +187,7 @@ function utils.setBit(value, bit)
end end
function utils.clearBit(value, bit) function utils.clearBit(value, bit)
if (value == nil) then return 0 end
if value % (2 * bit) >= bit then if value % (2 * bit) >= bit then
return value - bit return value - bit
end end