mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
WebGLLayer now re-renders itself at a lower resolution if it's too big.
This commit is contained in:
parent
61a25c5693
commit
5fe9a02c06
2 changed files with 13 additions and 0 deletions
|
@ -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) ->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue