Container renderings are now dependent on resolution.

This commit is contained in:
Scott Erickson 2014-09-17 16:49:31 -07:00
parent dbfbddeb5d
commit dd81d1d5bc
4 changed files with 19 additions and 14 deletions

View file

@ -10,7 +10,7 @@ CocoView = require 'views/kinds/CocoView'
marked.setOptions {gfm: true, sanitize: true, smartLists: true, breaks: false}
# TODO, add C-style macro constants like this?
window.SPRITE_RESOLUTION_FACTOR = 4
window.SPRITE_RESOLUTION_FACTOR = 1.5
# Prevent Ctrl/Cmd + [ / ], P, S
ctrlDefaultPrevented = [219, 221, 80, 83]

View file

@ -302,8 +302,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
updateBaseScale: ->
scale = 1
scale = @thangType.get('scale') or 1 if @isRaster
scale /= @options.resolutionFactor unless @isRaster
useRawScale = @isRaster or @thangType.get('renderStrategy') is 'container'
scale = @thangType.get('scale') or 1 if useRawScale
scale /= @options.resolutionFactor unless useRawScale
@baseScaleX = @baseScaleY = scale
@baseScaleX *= -1 if @getActionProp 'flipX'
@baseScaleY *= -1 if @getActionProp 'flipY'

View file

@ -41,6 +41,7 @@ module.exports = class WebGLLayer extends CocoClass
key
addCocoSprite: (cocoSprite) ->
cocoSprite.options.resolutionFactor = @resolutionFactor
@cocoSprites.push cocoSprite
@loadThangType(cocoSprite.thangType)
@addDefaultActionsToRender(cocoSprite)
@ -150,7 +151,7 @@ module.exports = class WebGLLayer extends CocoClass
for containerGlobalName in _.keys(containersToRender)
containerKey = @renderGroupingKey(thangType, containerGlobalName, colorConfig)
container = spriteBuilder.buildContainerFromStore(containerGlobalName)
frame = spriteSheetBuilder.addFrame(container)
frame = spriteSheetBuilder.addFrame(container, null, @resolutionFactor)
spriteSheetBuilder.addAnimation(containerKey, [frame], false)
getContainersForAnimation: (thangType, animation) ->
@ -239,7 +240,7 @@ module.exports = class WebGLLayer extends CocoClass
else
prefix = @renderGroupingKey(cocoSprite.thangType, null, cocoSprite.colorConfig) + '.'
sprite = new WebGLSprite(@spriteSheet, cocoSprite.thangType, prefix)
sprite = new WebGLSprite(@spriteSheet, cocoSprite.thangType, prefix, @resolutionFactor)
sprite.sprite = cocoSprite
sprite.layerPriority = cocoSprite.thang?.layerPriority ? cocoSprite.thangType.get 'layerPriority'

View file

@ -3,7 +3,7 @@ SpriteBuilder = require 'lib/sprites/SpriteBuilder'
module.exports = class WebGLSprite extends createjs.SpriteContainer
childMovieClips: null
constructor: (@spriteSheet, @thangType, @spriteSheetPrefix) ->
constructor: (@spriteSheet, @thangType, @spriteSheetPrefix, @resolutionFactor=SPRITE_RESOLUTION_FACTOR) ->
@initialize(@spriteSheet)
if @thangType.get('renderStrategy') isnt 'container'
@singleChildSprite = new createjs.Sprite(@spriteSheet)
@ -42,7 +42,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
@framerate = (action.framerate ? 20) * (action.speed ? 1)
if @singleChildSprite
scale = SPRITE_RESOLUTION_FACTOR * (action.scale ? @thangType.get('scale') ? 1)
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
@regX = -reg.x * scale
@regY = -reg.y * scale
func = if @paused then 'gotoAndStop' else 'gotoAndPlay'
@ -69,7 +69,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
if action.container
if @singleChildSprite
scale = SPRITE_RESOLUTION_FACTOR * (action.scale ? @thangType.get('scale') ? 1)
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
@regX = -reg.x * scale
@regY = -reg.y * scale
animationName = @spriteSheetPrefix + actionName
@ -123,12 +123,15 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
buildMovieClipContainers: (localContainers) ->
map = {}
for localContainer in localContainers
container = new createjs.Sprite(@spriteSheet)
container.gotoAndStop(@spriteSheetPrefix + localContainer.gn)
container.setTransform(localContainer.t...)
container._off = localContainer.o if localContainer.o?
container.alpha = localContainer.al if localContainer.al?
map[localContainer.bn] = container
outerContainer = new createjs.SpriteContainer(@spriteSheet)
innerContainer = new createjs.Sprite(@spriteSheet)
innerContainer.scaleX = innerContainer.scaleY = 1 / @resolutionFactor
innerContainer.gotoAndStop(@spriteSheetPrefix + localContainer.gn)
outerContainer.addChild(innerContainer)
outerContainer.setTransform(localContainer.t...)
outerContainer._off = localContainer.o if localContainer.o?
outerContainer.alpha = localContainer.al if localContainer.al?
map[localContainer.bn] = outerContainer
return map
buildMovieClipAnimations: (localAnimations) ->