Fixed the surface to not restore state until it's done dropping frames.

This commit is contained in:
Scott Erickson 2014-09-26 15:23:27 -07:00
parent 332f4700f6
commit b89a6c41a7

View file

@ -177,6 +177,7 @@ module.exports = Surface = class Surface extends CocoClass
oldFrame = @currentFrame oldFrame = @currentFrame
oldWorldFrame = Math.floor oldFrame oldWorldFrame = Math.floor oldFrame
lastFrame = @world.frames.length - 1 lastFrame = @world.frames.length - 1
framesDropped = 0
while true while true
Dropper.tick() Dropper.tick()
@trailmaster.tick() if @trailmaster @trailmaster.tick() if @trailmaster
@ -191,12 +192,15 @@ module.exports = Surface = class Surface extends CocoClass
@currentFrame += advanceBy @currentFrame += advanceBy
@currentFrame = Math.min @currentFrame, lastFrame @currentFrame = Math.min @currentFrame, lastFrame
newWorldFrame = Math.floor @currentFrame newWorldFrame = Math.floor @currentFrame
worldFrameAdvanced = newWorldFrame isnt oldWorldFrame if Dropper.drop()
if worldFrameAdvanced framesDropped += 1
# Only restore world state when it will correspond to an integer WorldFrame, not interpolated frame. else
@restoreWorldState() worldFrameAdvanced = newWorldFrame isnt oldWorldFrame
oldWorldFrame = newWorldFrame if worldFrameAdvanced
break unless Dropper.drop() # Only restore world state when it will correspond to an integer WorldFrame, not interpolated frame.
@restoreWorldState()
oldWorldFrame = newWorldFrame
break
if frameAdvanced and not worldFrameAdvanced if frameAdvanced and not worldFrameAdvanced
# We didn't end the above loop on an integer frame, so do the world state update. # We didn't end the above loop on an integer frame, so do the world state update.
@restoreWorldState() @restoreWorldState()