WebGLLayer now re-renders itself at a lower resolution if it's too big.

This commit is contained in:
Scott Erickson 2014-09-17 17:08:24 -07:00
parent 61a25c5693
commit 5fe9a02c06
2 changed files with 13 additions and 0 deletions

View file

@ -42,6 +42,7 @@ module.exports = class WebGLLayer extends CocoClass
addCocoSprite: (cocoSprite) ->
cocoSprite.options.resolutionFactor = @resolutionFactor
cocoSprite.updateBaseScale()
@cocoSprites.push cocoSprite
@loadThangType(cocoSprite.thangType)
@addDefaultActionsToRender(cocoSprite)
@ -122,6 +123,13 @@ module.exports = class WebGLLayer extends CocoClass
onBuildSpriteSheetComplete: (e, builder) ->
return if @initializing
if builder.spriteSheet._images.length > 1
@resolutionFactor *= 0.9
console.debug('Sprite sheet is too large... re-rendering at', @resolutionFactor.toFixed(2))
@_renderNewSpriteSheet()
return
@spriteSheet = builder.spriteSheet
oldLayer = @spriteContainer
@spriteContainer = new SpriteContainerLayer(@spriteSheet, @layerOptions)
@ -135,6 +143,10 @@ module.exports = class WebGLLayer extends CocoClass
parent.addChildAt(@spriteContainer, index)
@layerOptions.camera?.updateZoom(true)
@spriteContainer.updateLayerOrder()
for cocoSprite in @cocoSprites
cocoSprite.options.resolutionFactor = @resolutionFactor
cocoSprite.updateBaseScale()
cocoSprite.updateScale()
@trigger 'new-spritesheet'
renderContainers: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->

View file

@ -82,6 +82,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
containerName = @spriteSheetPrefix + action.container
sprite = new createjs.Sprite(@spriteSheet)
sprite.gotoAndStop(containerName)
sprite.scaleX = sprite.scaleY = 1 / @resolutionFactor
@children = [sprite]
return