Minor fixes

Making sure LayerAdapter doesn't wait for ThangType to load the image more than once.
LayerAdapter skips rendering if there's a prerendered sprite sheet whose image is not loaded.
This commit is contained in:
Scott Erickson 2015-10-14 14:48:43 -07:00
parent 305cffb5ea
commit b77626b8ee
2 changed files with 9 additions and 3 deletions

View file

@ -179,7 +179,8 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
@listenToOnce(thangType, 'raster-image-loaded', @somethingLoaded)
@numThingsLoading++
else if prerenderedSpriteSheet = thangType.getPrerenderedSpriteSheetToLoad()
prerenderedSpriteSheet.loadImage()
startedLoading = prerenderedSpriteSheet.loadImage()
return if not startedLoading
@listenToOnce(prerenderedSpriteSheet, 'image-loaded', -> @somethingLoaded(thangType))
@numThingsLoading++
@ -353,6 +354,8 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
renderSegmentedThangType: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->
prerenderedSpriteSheet = thangType.getPrerenderedSpriteSheet(colorConfig, 'segmented')
if prerenderedSpriteSheet and not prerenderedSpriteSheet.loadedImage
return
containersToRender = thangType.getContainersForActions(actionNames)
spriteBuilder = new SpriteBuilder(thangType, {colorConfig: colorConfig})
for containerGlobalName in containersToRender
@ -377,6 +380,8 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
prerenderedSpriteSheet = thangType.getPrerenderedSpriteSheet(colorConfig, 'singular')
prerenderedFramesMap = {}
if prerenderedSpriteSheet
if not prerenderedSpriteSheet.loadedImage
return
scale = @resolutionFactor / (prerenderedSpriteSheet.get('resolutionFactor') or 1)
for frame, i in prerenderedSpriteSheet.spriteSheet._frames
sprite = new createjs.Sprite(prerenderedSpriteSheet.spriteSheet)

View file

@ -541,8 +541,8 @@ class PrerenderedSpriteSheet extends CocoModel
@className: 'PrerenderedSpriteSheet'
loadImage: ->
return if @loadingImage or @loadedImage
return unless imageURL = @get('image')
return false if @loadingImage or @loadedImage
return false unless imageURL = @get('image')
@image = $("<img src='/file/#{imageURL}' />")
@loadingImage = true
@image.one('load', =>
@ -554,6 +554,7 @@ class PrerenderedSpriteSheet extends CocoModel
@loadingImage = false
@trigger('image-load-error', @)
)
return true
buildSpriteSheet: ->
@spriteSheet = new createjs.SpriteSheet({