mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
Fixed some bugs with sprite sound loading and playback.
This commit is contained in:
parent
65aae86dcc
commit
ca6ea474bf
2 changed files with 12 additions and 10 deletions
|
@ -63,8 +63,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
console.error @toString(), "has no ThangType!" unless @thangType
|
||||
|
||||
# this is a stub, use @setImageObject to swap it out for something else later
|
||||
@imageObject = new createjs.Container
|
||||
|
||||
@imageObject = new createjs.Container
|
||||
|
||||
@actionQueue = []
|
||||
@marks = {}
|
||||
@labels = {}
|
||||
|
@ -80,6 +80,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@listenToOnce(@thangType, 'sync', @setupSprite)
|
||||
|
||||
setupSprite: ->
|
||||
for trigger, sounds of @thangType.get('soundTriggers') or {} when trigger isnt 'say'
|
||||
AudioPlayer.preloadSoundReference sound for sound in sounds
|
||||
@stillLoading = false
|
||||
if @thangType.get('raster')
|
||||
@isRaster = true
|
||||
|
@ -121,7 +123,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
options.colorConfig = @options.colorConfig if @options.colorConfig
|
||||
options.async = false
|
||||
@thangType.getSpriteSheet options
|
||||
|
||||
|
||||
setImageObject: (newImageObject) ->
|
||||
if parent = @imageObject?.parent
|
||||
parent.removeChild @imageObject
|
||||
|
@ -287,7 +289,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@imageObject.regX += bounds.width / 2
|
||||
@imageObject.regY ?= 0
|
||||
@imageObject.regY += bounds.height / 2
|
||||
|
||||
|
||||
unless @thang.spriteName is 'Beam'
|
||||
@imageObject.scaleX *= @thangType.get('scale') ? 1
|
||||
@imageObject.scaleY *= @thangType.get('scale') ? 1
|
||||
|
@ -308,12 +310,12 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
angle = -angle if angle < 0
|
||||
angle = 180 - angle if angle > 90
|
||||
scaleX = 0.5 + 0.5 * (90 - angle) / 90
|
||||
|
||||
|
||||
if @isRaster # scale is worked into building the sprite sheet for animations
|
||||
scale = @thangType.get('scale') or 1
|
||||
scaleX *= scale
|
||||
scaleY *= scale
|
||||
|
||||
|
||||
scaleFactorX = @thang.scaleFactorX ? @scaleFactor
|
||||
scaleFactorY = @thang.scaleFactorY ? @scaleFactor
|
||||
@imageObject.scaleX = @originalScaleX * scaleX * scaleFactorX
|
||||
|
@ -490,7 +492,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
if not @isRaster
|
||||
scale = @getActionProp 'scale', null, 1
|
||||
scale *= @options.resolutionFactor if prop is 'registration'
|
||||
pos.x *= scale
|
||||
pos.x *= scale
|
||||
pos.y *= scale
|
||||
if @thang and prop isnt 'registration'
|
||||
scaleFactor = @thang.scaleFactor ? 1
|
||||
|
@ -674,7 +676,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
delay = if withDelay and sound.delay then 1000 * sound.delay / createjs.Ticker.getFPS() else 0
|
||||
name = AudioPlayer.nameForSoundReference sound
|
||||
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
|
||||
|
||||
onMove: (e) ->
|
||||
|
|
|
@ -201,7 +201,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
return if @cached and not update
|
||||
wallSprites = (sprite for sprite in @spriteArray when sprite.thangType?.get('name').search(/(dungeon|indoor).wall/i) isnt -1)
|
||||
unless _.all (s.thangType.isFullyLoaded() for s in wallSprites)
|
||||
return
|
||||
return
|
||||
walls = (sprite.thang for sprite in wallSprites)
|
||||
@world.calculateBounds()
|
||||
wallGrid = new Grid walls, @world.size()...
|
||||
|
@ -272,7 +272,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
@selectedSprite?.selected = false
|
||||
sprite?.selected = true
|
||||
@selectedSprite = sprite
|
||||
alive = sprite?.thang.health > 0
|
||||
alive = not (sprite?.thang.health < 0)
|
||||
|
||||
Backbone.Mediator.publish 'surface:sprite-selected',
|
||||
thang: if sprite then sprite.thang else null
|
||||
|
|
Loading…
Reference in a new issue