This commit is contained in:
Nick Winter 2014-08-26 15:22:13 -07:00
parent 50ad453345
commit a5c18a4140
2 changed files with 9 additions and 6 deletions

View file

@ -89,8 +89,10 @@ class AudioPlayer extends CocoClass
playSound: (name, volume=1, delay=0, pos=null) -> playSound: (name, volume=1, delay=0, pos=null) ->
audioOptions = {volume: (me.get('volume') ? 1) * volume, delay: delay} audioOptions = {volume: (me.get('volume') ? 1) * volume, delay: delay}
unless @camera is null or pos is null filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name
audioOptions = @applyPanning audioOptions, pos unless (filename of cache) and createjs.Sound.loadComplete filename
@soundsToPlayWhenLoaded[name] = audioOptions.volume
audioOptions = @applyPanning audioOptions, pos if @camera and pos
instance = createjs.Sound.play name, audioOptions instance = createjs.Sound.play name, audioOptions
instance instance

View file

@ -678,14 +678,14 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
label = @addLabel 'dialogue', Label.STYLE_DIALOGUE label = @addLabel 'dialogue', Label.STYLE_DIALOGUE
label.setText e.blurb or '...' label.setText e.blurb or '...'
sound = e.sound ? AudioPlayer.soundForDialogue e.message, @thangType.get 'soundTriggers' sound = e.sound ? AudioPlayer.soundForDialogue e.message, @thangType.get 'soundTriggers'
@instance?.stop() @dialogueSoundInstance?.stop()
if @instance = @playSound sound, false if @dialogueSoundInstance = @playSound sound, false
@instance.addEventListener 'complete', -> Backbone.Mediator.publish 'dialogue-sound-completed' @dialogueSoundInstance.addEventListener 'complete', -> Backbone.Mediator.publish 'dialogue-sound-completed'
@notifySpeechUpdated e @notifySpeechUpdated e
onClearDialogue: (e) -> onClearDialogue: (e) ->
@labels.dialogue?.setText null @labels.dialogue?.setText null
@instance?.stop() @dialogueSoundInstance?.stop()
@notifySpeechUpdated {} @notifySpeechUpdated {}
setNameLabel: (name) -> setNameLabel: (name) ->
@ -733,6 +733,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
return null unless sound return null unless sound
delay = if withDelay and sound.delay then 1000 * sound.delay / createjs.Ticker.getFPS() else 0 delay = if withDelay and sound.delay then 1000 * sound.delay / createjs.Ticker.getFPS() else 0
name = AudioPlayer.nameForSoundReference sound name = AudioPlayer.nameForSoundReference sound
AudioPlayer.preloadSoundReference sound
instance = AudioPlayer.playSound name, volume, delay, @getWorldPosition() instance = AudioPlayer.playSound name, volume, delay, @getWorldPosition()
#console.log @thang?.id, 'played sound', name, 'with delay', delay, 'volume', volume, 'and got sound instance', instance #console.log @thang?.id, 'played sound', name, 'with delay', delay, 'volume', volume, 'and got sound instance', instance
instance instance