From f9409488ff73f281b91f1803082f3fe662d7768b Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Wed, 8 Oct 2014 12:38:23 -0700 Subject: [PATCH] Fixed a bug with jerky camera udpates due to dropped frames and camera updating before positions update. Fleshed out default level scripts. Tweaked style on Dropper code. --- app/lib/DefaultScripts.coffee | 17 +++++++++++++++-- app/lib/surface/Dropper.coffee | 21 ++++++++++----------- app/lib/surface/Surface.coffee | 4 ++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/lib/DefaultScripts.coffee b/app/lib/DefaultScripts.coffee index 8417ce978..818feee91 100644 --- a/app/lib/DefaultScripts.coffee +++ b/app/lib/DefaultScripts.coffee @@ -1,7 +1,20 @@ module.exports = [ { - channel: "god:new-world-created" - noteChain: [] id: "Introduction" + channel: "god:new-world-created" + noteChain: [ + name: "Set camera, start music." + surface: + focus: + bounds: [{x: 0, y: 0}, {x: 80, y: 68}] + target: "Hero Placeholder" + zoom: 2 + sound: + music: + file: "/music/music_level_2" + play: true + script: + duration: 1 + ] } ] diff --git a/app/lib/surface/Dropper.coffee b/app/lib/surface/Dropper.coffee index e7ea3c6cd..f074c702b 100644 --- a/app/lib/surface/Dropper.coffee +++ b/app/lib/surface/Dropper.coffee @@ -1,28 +1,27 @@ Dropper = class Dropper - lost_frames: 0.0 - drop_counter: 0 + lostFrames: 0.0 + dropCounter: 0 constructor: -> @listener = (e) => @tick(e) tick: -> unless @tickedOnce - @tickedOnce = true # Can't get measured FPS on the 0th frame + @tickedOnce = true # Can't get measured FPS on the 0th frame. return - # decrement drop counter - @drop_counter -= 1 if @drop_counter > 0 + --@dropCounter if @dropCounter > 0 - # track number of frames we've lost since the last tick + # Track number of frames we've lost since the last tick. fps = createjs.Ticker.getFPS() actual = createjs.Ticker.getMeasuredFPS(1) - @lost_frames += (fps - actual) / fps + @lostFrames += (fps - actual) / fps - # if lost_frames > 1, drop that number for the next tick - @drop_counter += parseInt(@lost_frames) - @lost_frames = @lost_frames % 1 + # If lostFrames > 1, drop that number for the next tick. + @dropCounter += parseInt @lostFrames + @lostFrames = @lostFrames % 1 drop: -> - return @drop_counter > 0 + return @dropCounter > 0 module.exports = new Dropper() diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index b96203fd4..617dbd279 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -193,7 +193,7 @@ module.exports = Surface = class Surface extends CocoClass @currentFrame = Math.min @currentFrame, lastFrame newWorldFrame = Math.floor @currentFrame if Dropper.drop() - framesDropped += 1 + ++framesDropped else worldFrameAdvanced = newWorldFrame isnt oldWorldFrame if worldFrameAdvanced @@ -232,8 +232,8 @@ module.exports = Surface = class Surface extends CocoClass # world state must have been restored in @restoreWorldState if @playing and @currentFrame < @world.frames.length - 1 and @heroLank and not @mouseIsDown and @camera.newTarget isnt @heroLank.sprite and @camera.target isnt @heroLank.sprite @camera.zoomTo @heroLank.sprite, @camera.zoom, 750 - @camera.updateZoom() @lankBoss.update frameChanged + @camera.updateZoom() # Make sure to do this right after the LankBoss updates, not before, so it can properly target sprite positions. @dimmer?.setSprites @lankBoss.lanks drawCurrentFrame: (e) ->