Refactored ticker, fixed from all instances were using same ticker.
This commit is contained in:
parent
b5bb1b13a1
commit
d50c362286
2 changed files with 11 additions and 14 deletions
app/lib/surface
|
@ -6,9 +6,6 @@ Mark = require './Mark'
|
||||||
Label = require './Label'
|
Label = require './Label'
|
||||||
AudioPlayer = require 'lib/AudioPlayer'
|
AudioPlayer = require 'lib/AudioPlayer'
|
||||||
|
|
||||||
#For bobbing
|
|
||||||
ticker = 0
|
|
||||||
|
|
||||||
# We'll get rid of this once level's teams actually have colors
|
# We'll get rid of this once level's teams actually have colors
|
||||||
healthColors =
|
healthColors =
|
||||||
ogres: [64, 128, 212]
|
ogres: [64, 128, 212]
|
||||||
|
@ -55,6 +52,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
'level-sprite-dialogue': 'onDialogue'
|
'level-sprite-dialogue': 'onDialogue'
|
||||||
'level-sprite-clear-dialogue': 'onClearDialogue'
|
'level-sprite-clear-dialogue': 'onClearDialogue'
|
||||||
'level-set-letterbox': 'onSetLetterbox'
|
'level-set-letterbox': 'onSetLetterbox'
|
||||||
|
'surface:ticked': 'onSurfaceTicked'
|
||||||
|
|
||||||
constructor: (@thangType, options) ->
|
constructor: (@thangType, options) ->
|
||||||
super()
|
super()
|
||||||
|
@ -66,6 +64,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@labels = {}
|
@labels = {}
|
||||||
@actions = @thangType.getActions()
|
@actions = @thangType.getActions()
|
||||||
@buildFromSpriteSheet @buildSpriteSheet()
|
@buildFromSpriteSheet @buildSpriteSheet()
|
||||||
|
@ticker = 0
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
|
@ -115,6 +114,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@playNextAction()
|
@playNextAction()
|
||||||
|
|
||||||
onActionEnd: (e) => @playNextAction()
|
onActionEnd: (e) => @playNextAction()
|
||||||
|
onSurfaceTicked: -> @ticker += 1
|
||||||
|
|
||||||
playNextAction: ->
|
playNextAction: ->
|
||||||
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
||||||
|
@ -150,9 +150,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
|
|
||||||
updatePosition: ->
|
updatePosition: ->
|
||||||
return unless @thang?.pos and @options.camera?
|
return unless @thang?.pos and @options.camera?
|
||||||
if 'bobs' in @thang.trackedPropertiesKeys
|
if @thang.bobHeight
|
||||||
ticker++
|
@thang.pos.z = @thang.pos.z + (Math.sin @ticker / @thang.bobTime) * 0.1 * @thang.bobHeight
|
||||||
@thang.pos.z = @thang.pos.z + (Math.sin ticker / (1 / @thang.bobSpeed) * .01 * @thang.bobHeight
|
|
||||||
[p0, p1] = [@lastPos, @thang.pos]
|
[p0, p1] = [@lastPos, @thang.pos]
|
||||||
return if p0 and p0.x is p1.x and p0.y is p1.y and p0.z is p1.z and not @options.camera.tweeningZoomTo
|
return if p0 and p0.x is p1.x and p0.y is p1.y and p0.z is p1.z and not @options.camera.tweeningZoomTo
|
||||||
wop = x: p1.x, y: p1.y, z: if @thang.isLand then 0 else p1.z - @thang.depth / 2
|
wop = x: p1.x, y: p1.y, z: if @thang.isLand then 0 else p1.z - @thang.depth / 2
|
||||||
|
|
|
@ -22,7 +22,6 @@ module.exports = class WizardSprite extends IndieSprite
|
||||||
'bus:player-states-changed': 'onPlayerStatesChanged'
|
'bus:player-states-changed': 'onPlayerStatesChanged'
|
||||||
'me:synced': 'onMeSynced'
|
'me:synced': 'onMeSynced'
|
||||||
'surface:sprite-selected': 'onSpriteSelected'
|
'surface:sprite-selected': 'onSpriteSelected'
|
||||||
'surface:ticked': 'onSurfaceTicked'
|
|
||||||
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
|
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
|
||||||
'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
|
'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
|
||||||
|
|
||||||
|
@ -103,7 +102,6 @@ module.exports = class WizardSprite extends IndieSprite
|
||||||
onEchoAllWizardSprites: (e) -> e.payload.push @
|
onEchoAllWizardSprites: (e) -> e.payload.push @
|
||||||
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @spriteZOffset
|
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @spriteZOffset
|
||||||
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
|
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
|
||||||
onSurfaceTicked: -> @ticker += 1
|
|
||||||
move: (pos, duration) -> @setTarget(pos, duration)
|
move: (pos, duration) -> @setTarget(pos, duration)
|
||||||
|
|
||||||
setTarget: (newTarget, duration) ->
|
setTarget: (newTarget, duration) ->
|
||||||
|
|
Reference in a new issue