mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
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.
This commit is contained in:
parent
589c3b090c
commit
f9409488ff
3 changed files with 27 additions and 15 deletions
|
@ -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
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue