mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Bunch more work on scaling for everything and hit testing for segmented sprites. Also got health bars working again.
This commit is contained in:
parent
6669a01c14
commit
7f90ed18cc
10 changed files with 189 additions and 302 deletions
|
@ -41,8 +41,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
rotation: 0
|
||||
|
||||
# Scale numbers
|
||||
baseScaleX: 1 # scale + flip (for current action) / resolutionFactor.
|
||||
baseScaleY: 1 # These numbers rarely change, so keep them around.
|
||||
scaleFactorX: 1 # Current scale adjustment. This can change rapidly.
|
||||
scaleFactorY: 1
|
||||
targetScaleFactorX: 1 # What the scaleFactor is going toward during a tween.
|
||||
|
@ -92,7 +90,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@actions = @thangType.getActions()
|
||||
@createMarks()
|
||||
|
||||
@updateBaseScale()
|
||||
@scaleFactorX = @thang.scaleFactorX if @thang?.scaleFactorX?
|
||||
@scaleFactorX = @thang.scaleFactor if @thang?.scaleFactor?
|
||||
@scaleFactorY = @thang.scaleFactorY if @thang?.scaleFactorY?
|
||||
|
@ -140,7 +137,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@currentAction = action
|
||||
return @hide() unless action.animation or action.container or action.relatedActions
|
||||
@show()
|
||||
@updateBaseScale()
|
||||
return @updateActionDirection() unless action.animation or action.container
|
||||
m = if action.container then 'gotoAndStop' else 'gotoAndPlay'
|
||||
@imageObject[m]?(action.name)
|
||||
|
@ -183,7 +179,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@updateLabels()
|
||||
|
||||
showAreaOfEffects: ->
|
||||
# TODO: add back area of effects
|
||||
return unless @thang?.currentEvents
|
||||
for event in @thang.currentEvents
|
||||
continue unless event.startsWith 'aoe-'
|
||||
|
@ -277,19 +272,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
# Let the pending flags know we're here (but not this call stack, they need to delete themselves, and we may be iterating sprites).
|
||||
_.defer => Backbone.Mediator.publish 'surface:flag-appeared', sprite: @
|
||||
|
||||
updateBaseScale: ->
|
||||
scale = 1
|
||||
useRawScale = @isRaster or @thangType.get('spriteType') 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'
|
||||
# temp, until these are re-exported with perspective
|
||||
floors = ['Dungeon Floor', 'Indoor Floor', 'Grass', 'Grass01', 'Grass02', 'Grass03', 'Grass04', 'Grass05', 'Goal Trigger', 'Obstacle']
|
||||
if @options.camera and @thangType.get('name') in floors
|
||||
@baseScaleY *= @options.camera.y2x
|
||||
|
||||
updateScale: ->
|
||||
return unless @imageObject
|
||||
if @thangType.get('matchWorldDimensions') and @thang
|
||||
|
@ -324,8 +306,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
scaleX = 0.5 + 0.5 * (90 - angle) / 90
|
||||
|
||||
# console.error 'No thang for', @ unless @thang
|
||||
@imageObject.scaleX = @baseScaleX * @scaleFactorX * scaleX
|
||||
@imageObject.scaleY = @baseScaleY * @scaleFactorY * scaleY
|
||||
@imageObject.scaleX = @imageObject.baseScaleX * @scaleFactorX * scaleX
|
||||
@imageObject.scaleY = @imageObject.baseScaleY * @scaleFactorY * scaleY
|
||||
|
||||
newScaleFactorX = @thang?.scaleFactorX ? @thang?.scaleFactor ? 1
|
||||
newScaleFactorY = @thang?.scaleFactorY ? @thang?.scaleFactor ? 1
|
||||
|
@ -461,9 +443,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@lastHealth = @thang.health
|
||||
if bar = @healthBar
|
||||
healthPct = Math.max(@thang.health / @thang.maxHealth, 0)
|
||||
bar.scaleX = healthPct / bar.baseScale
|
||||
healthOffset = @getOffset 'aboveHead'
|
||||
[bar.x, bar.y] = [healthOffset.x - bar.width / 2, healthOffset.y]
|
||||
bar.scaleX = healthPct / @options.floatingLayer.resolutionFactor
|
||||
if @thang.showsName
|
||||
@setNameLabel(if @thang.health <= 0 then '' else @thang.id)
|
||||
|
||||
|
@ -486,15 +466,23 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
Backbone.Mediator.publish ourEventName, newEvent
|
||||
|
||||
addHealthBar: ->
|
||||
# TODO: Put back in health bars
|
||||
# return unless @thang?.health? and 'health' in (@thang?.hudProperties ? []) and @options.floatingLayer
|
||||
# healthColor = healthColors[@thang?.team] ? healthColors['neutral']
|
||||
# healthOffset = @getOffset 'aboveHead'
|
||||
# bar = @healthBar = createProgressBar(healthColor, healthOffset)
|
||||
# bar.name = 'health bar'
|
||||
# bar.cache 0, -bar.height * bar.baseScale / 2, bar.width * bar.baseScale, bar.height * bar.baseScale
|
||||
# @options.floatingLayer.addChild bar
|
||||
# @updateHealthBar()
|
||||
return unless @thang?.health? and 'health' in (@thang?.hudProperties ? []) and @options.floatingLayer
|
||||
team = @thang?.team or 'neutral'
|
||||
key = "#{team}-health-bar"
|
||||
|
||||
unless key in @options.floatingLayer.spriteSheet.getAnimations()
|
||||
healthColor = healthColors[team]
|
||||
bar = createProgressBar(healthColor)
|
||||
@options.floatingLayer.addCustomGraphic(key, bar, bar.bounds)
|
||||
|
||||
@healthBar = new createjs.Sprite(@options.floatingLayer.spriteSheet)
|
||||
@healthBar.gotoAndStop(key)
|
||||
offset = @getOffset 'aboveHead'
|
||||
@healthBar.scaleX = @healthBar.scaleY = 1 / @options.floatingLayer.resolutionFactor
|
||||
@healthBar.name = 'health bar'
|
||||
@options.floatingLayer.addChild @healthBar
|
||||
@updateHealthBar()
|
||||
@lastHealth = null
|
||||
|
||||
getActionProp: (prop, subProp, def=null) ->
|
||||
# Get a property or sub-property from an action, falling back to ThangType
|
||||
|
@ -768,8 +756,10 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
|
||||
updateHealthBar: ->
|
||||
return unless @healthBar
|
||||
@healthBar.x = @imageObject.x
|
||||
@healthBar.y = @imageObject.y
|
||||
bounds = @healthBar.getBounds()
|
||||
offset = @getOffset 'aboveHead'
|
||||
@healthBar.x = @imageObject.x - (-offset.x + bounds.width / 2 / @options.floatingLayer.resolutionFactor)
|
||||
@healthBar.y = @imageObject.y - (-offset.y + bounds.height / 2 / @options.floatingLayer.resolutionFactor)
|
||||
|
||||
destroy: ->
|
||||
mark.destroy() for name, mark of @marks
|
||||
|
|
|
@ -154,13 +154,13 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
console.warn 'CocoSprite being re-added to a layer?'
|
||||
|
||||
cocoSprite.layer = @
|
||||
cocoSprite.updateBaseScale()
|
||||
@listenTo(cocoSprite, 'action-needs-render', @onActionNeedsRender)
|
||||
@cocoSprites.push cocoSprite
|
||||
@loadThangType(cocoSprite.thangType)
|
||||
@addDefaultActionsToRender(cocoSprite)
|
||||
@setImageObjectToCocoSprite(cocoSprite)
|
||||
@updateLayerOrder()
|
||||
cocoSprite.addHealthBar()
|
||||
|
||||
removeCocoSprite: (cocoSprite) ->
|
||||
@stopListening(cocoSprite)
|
||||
|
@ -288,7 +288,6 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
@updateLayerOrder()
|
||||
for cocoSprite in @cocoSprites
|
||||
cocoSprite.options.resolutionFactor = @resolutionFactor
|
||||
cocoSprite.updateBaseScale()
|
||||
cocoSprite.updateScale()
|
||||
cocoSprite.updateRotation()
|
||||
@trigger 'new-spritesheet'
|
||||
|
@ -444,9 +443,9 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
sprite = new SpriteClass(@spriteSheet, cocoSprite.thangType, prefix, @resolutionFactor)
|
||||
|
||||
sprite.sprite = cocoSprite
|
||||
sprite.camera = @camera
|
||||
sprite.layerPriority = cocoSprite.thang?.layerPriority ? cocoSprite.thangType.get 'layerPriority'
|
||||
sprite.name = cocoSprite.thang?.spriteName or cocoSprite.thangType.get 'name'
|
||||
cocoSprite.addHealthBar()
|
||||
cocoSprite.setImageObject(sprite)
|
||||
cocoSprite.update(true)
|
||||
@container.addChild(sprite)
|
||||
|
|
|
@ -30,27 +30,30 @@ module.exports = class SegmentedSprite extends createjs.SpriteContainer
|
|||
# because the resulting segmented image is set to the size of the movie clip, you can use
|
||||
# the raw registration data without scaling it.
|
||||
reg = action.positions?.registration or @thangType.get('positions')?.registration or {x:0, y:0}
|
||||
@regX = -reg.x
|
||||
@regY = -reg.y
|
||||
@baseScaleY = @baseScaleX = action.scale ? @thangType.get('scale') ? 1
|
||||
|
||||
|
||||
if action.animation
|
||||
@regX = -reg.x
|
||||
@regY = -reg.y
|
||||
@framerate = (action.framerate ? 20) * (action.speed ? 1)
|
||||
@childMovieClips = []
|
||||
@baseMovieClip = @buildMovieClip(action.animation)
|
||||
@children = @baseMovieClip.children
|
||||
@frames = action.frames
|
||||
@frames = (parseInt(f) for f in @frames.split(',')) if @frames
|
||||
@animLength = if @frames then @frames.length else @baseMovieClip.frameBounds.length
|
||||
@currentFrame = if randomStart then Math.floor(Math.random() * @animLength) else 0
|
||||
@baseMovieClip.gotoAndStop(@currentFrame)
|
||||
movieClip.gotoAndStop(@currentFrame) for movieClip in @childMovieClips
|
||||
@takeChildrenFromMovieClip()
|
||||
@loop = action.loops isnt false
|
||||
@goesTo = action.goesTo
|
||||
@notifyActionNeedsRender(action) if @actionNotSupported
|
||||
@updateBaseMovieClip()
|
||||
|
||||
@scaleX = @scaleY = action.scale ? @thangType.get('scale') ? 1
|
||||
|
||||
else if action.container
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
# All transformations will be done to the child sprite
|
||||
@regX = @regY = 0
|
||||
@scaleX = @scaleY = 1
|
||||
|
||||
@childMovieClips = []
|
||||
containerName = @spriteSheetPrefix + action.container
|
||||
sprite = new createjs.Sprite(@spriteSheet)
|
||||
|
@ -60,21 +63,25 @@ module.exports = class SegmentedSprite extends createjs.SpriteContainer
|
|||
sprite.gotoAndStop(0)
|
||||
@notifyActionNeedsRender(action)
|
||||
bounds = @thangType.get('raw').containers[action.container].b
|
||||
sprite.x = bounds[0]
|
||||
sprite.y = bounds[1]
|
||||
sprite.scaleX = bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
sprite.scaleY = bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
actionScale = (action.scale ? @thangType.get('scale') ? 1)
|
||||
sprite.scaleX = actionScale * bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
sprite.scaleY = actionScale * bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
sprite.regX = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.x - bounds[0]) / bounds[2])
|
||||
sprite.regY = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.y - bounds[1]) / bounds[3])
|
||||
else
|
||||
sprite.scaleX = sprite.scaleY = 1 / scale
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
sprite.regX = -reg.x * scale
|
||||
sprite.regY = -reg.y * scale
|
||||
sprite.scaleX = sprite.scaleY = 1 / @resolutionFactor
|
||||
@children = []
|
||||
@addChild(sprite)
|
||||
|
||||
@scaleX *= -1 if action.flipX
|
||||
@scaleY *= -1 if action.flipY
|
||||
@baseScaleX = @scaleX
|
||||
@baseScaleY = @scaleY
|
||||
return
|
||||
|
||||
updateBaseMovieClip: ->
|
||||
return unless @baseMovieClip
|
||||
@baseMovieClip[prop] = @[prop] for prop in ['x', 'y', 'regX', 'regY']
|
||||
|
||||
notifyActionNeedsRender: (action) ->
|
||||
@sprite?.trigger('action-needs-render', @sprite, action)
|
||||
|
||||
|
@ -202,15 +209,32 @@ module.exports = class SegmentedSprite extends createjs.SpriteContainer
|
|||
@baseMovieClip.gotoAndStop(newFrame)
|
||||
|
||||
@currentFrame = newFrame
|
||||
@children = []
|
||||
|
||||
# So, originally I thought I'd have to swap in MovieClips for parallel
|
||||
# SpriteContainers between each frame, but turns out that's not the case.
|
||||
# The WebGL rendering system treats the MovieClip like a SpriteContainer,
|
||||
# which makes things simpler for me...
|
||||
|
||||
# For some reason, though, gotoAndStop doesn't seem to advance the children
|
||||
# so I gotta do that manually.
|
||||
movieClip.gotoAndStop(newFrame) for movieClip in @childMovieClips
|
||||
@takeChildrenFromMovieClip()
|
||||
|
||||
takeChildrenFromMovieClip: ->
|
||||
i = 0
|
||||
while i < @baseMovieClip.children.length
|
||||
child = @baseMovieClip.children[i]
|
||||
if child instanceof createjs.MovieClip
|
||||
newChild = new createjs.SpriteContainer(@spriteSheet)
|
||||
j = 0
|
||||
while j < child.children.length
|
||||
grandChild = child.children[j]
|
||||
if grandChild instanceof createjs.MovieClip
|
||||
console.error('MovieClip Segmentedsprites not currently working at this depth!')
|
||||
continue
|
||||
newChild.addChild(grandChild)
|
||||
for prop in ['regX', 'regY', 'rotation', 'scaleX', 'scaleY', 'skewX', 'skewY', 'x', 'y']
|
||||
newChild[prop] = child[prop]
|
||||
@addChild(newChild)
|
||||
@alreadyLogged = true
|
||||
i += 1
|
||||
else
|
||||
@addChild(child)
|
||||
|
||||
|
||||
getBounds: ->
|
||||
@baseMovieClip.getBounds()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
||||
|
||||
floors = ['Dungeon Floor', 'Indoor Floor', 'Grass', 'Grass01', 'Grass02', 'Grass03', 'Grass04', 'Grass05', 'Goal Trigger', 'Obstacle']
|
||||
|
||||
module.exports = class WebGLSprite extends createjs.Sprite
|
||||
childMovieClips: null
|
||||
|
||||
|
@ -24,11 +26,6 @@ module.exports = class WebGLSprite extends createjs.Sprite
|
|||
if action.animation
|
||||
@framerate = (action.framerate ? 20) * (action.speed ? 1)
|
||||
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
@regX = -reg.x * scale
|
||||
@regY = -reg.y * scale
|
||||
@scaleX = @baseScaleX = 1 / scale
|
||||
@scaleY = @baseScaleY = 1 / scale
|
||||
func = if @paused then '_gotoAndStop' else '_gotoAndPlay'
|
||||
animationName = @spriteSheetPrefix + actionName
|
||||
@[func](animationName)
|
||||
|
@ -36,37 +33,44 @@ module.exports = class WebGLSprite extends createjs.Sprite
|
|||
@_gotoAndStop(0)
|
||||
@notifyActionNeedsRender(action)
|
||||
bounds = @thangType.get('raw').animations[action.animation].bounds
|
||||
@scaleX = bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@scaleY = bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@regX = (- reg.x - bounds[0]) / @scaleX
|
||||
@regY = (- reg.y - bounds[1]) / @scaleY
|
||||
return
|
||||
|
||||
@framerate = action.framerate or 20
|
||||
if randomStart and frames = @spriteSheet.getAnimation(animationName)?.frames
|
||||
@currentAnimationFrame = Math.floor(Math.random() * frames.length)
|
||||
actionScale = (action.scale ? @thangType.get('scale') ? 1)
|
||||
@scaleX = actionScale * bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@scaleY = actionScale * bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@regX = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.x - bounds[0]) / bounds[2])
|
||||
@regY = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.y - bounds[1]) / bounds[3])
|
||||
else
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
@regX = -reg.x * scale
|
||||
@regY = -reg.y * scale
|
||||
@scaleX = @scaleY = 1 / @resolutionFactor
|
||||
@framerate = action.framerate or 20
|
||||
if randomStart and frames = @spriteSheet.getAnimation(animationName)?.frames
|
||||
@currentAnimationFrame = Math.floor(Math.random() * frames.length)
|
||||
|
||||
if action.container
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
@regX = -reg.x * scale
|
||||
@regY = -reg.y * scale
|
||||
@scaleX = @scaleY = @baseScaleX = @baseScaleY = 1 / scale
|
||||
animationName = @spriteSheetPrefix + actionName
|
||||
@_gotoAndStop(animationName)
|
||||
if @currentFrame is 0 or @usePlaceholders
|
||||
@_gotoAndStop(0)
|
||||
@notifyActionNeedsRender(action)
|
||||
bounds = @thangType.get('raw').containers[action.container].b
|
||||
@scaleX = @baseScaleX = bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@scaleY = @baseScaleY = bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@regX = (bounds[0] - reg.x) / @scaleX
|
||||
@regY = (bounds[1] - reg.y) / @scaleY
|
||||
# I don't think you can properly position the placeholder without either
|
||||
# tying regX/Y to scaleX/Y or having this be a container within a container.
|
||||
# This means if the placeholder has its scale changed from outside, the
|
||||
# registration positioning will be off. Hopefully this won't matter.
|
||||
return
|
||||
actionScale = (action.scale ? @thangType.get('scale') ? 1)
|
||||
@scaleX = actionScale * bounds[2] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@scaleY = actionScale * bounds[3] / (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor)
|
||||
@regX = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.x - bounds[0]) / bounds[2])
|
||||
@regY = (SPRITE_PLACEHOLDER_WIDTH * @resolutionFactor) * ((-reg.y - bounds[1]) / bounds[3])
|
||||
else
|
||||
scale = @resolutionFactor * (action.scale ? @thangType.get('scale') ? 1)
|
||||
@regX = -reg.x * scale
|
||||
@regY = -reg.y * scale
|
||||
@scaleX = @scaleY = 1 / @resolutionFactor
|
||||
|
||||
if @camera and @thangType.get('name') in floors
|
||||
@baseScaleY *= @options.camera.y2x
|
||||
@scaleX *= -1 if action.flipX
|
||||
@scaleY *= -1 if action.flipY
|
||||
@baseScaleX = @scaleX
|
||||
@baseScaleY = @scaleY
|
||||
@currentAnimation = actionName
|
||||
return
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ module.exports = class WizardSprite extends IndieSprite
|
|||
thang
|
||||
|
||||
finishSetup: ->
|
||||
@updateBaseScale()
|
||||
@scaleFactor = @thang.scaleFactor if @thang?.scaleFactor
|
||||
@updateScale()
|
||||
@updateRotation()
|
||||
|
|
|
@ -1,28 +1,15 @@
|
|||
PROG_BAR_WIDTH = 20
|
||||
PROG_BAR_HEIGHT = 2
|
||||
PROG_BAR_SCALE = 2.5
|
||||
EDGE_SIZE = 0.3
|
||||
WIDTH = 20
|
||||
HEIGHT = 2
|
||||
EDGE = 0.3
|
||||
|
||||
module.exports.createProgressBar = createProgressBar = (color, offset, width=PROG_BAR_WIDTH, height=PROG_BAR_HEIGHT) ->
|
||||
module.exports.createProgressBar = createProgressBar = (color) ->
|
||||
g = new createjs.Graphics()
|
||||
g.setStrokeStyle(1)
|
||||
|
||||
sWidth = width * PROG_BAR_SCALE
|
||||
sHeight = height * PROG_BAR_SCALE
|
||||
sEdge = EDGE_SIZE * PROG_BAR_SCALE
|
||||
|
||||
g.beginFill(createjs.Graphics.getRGB(0, 0, 0))
|
||||
g.drawRect(0, -sHeight/2, sWidth, sHeight, sHeight)
|
||||
g.drawRect(0, -HEIGHT/2, WIDTH, HEIGHT, HEIGHT)
|
||||
g.beginFill(createjs.Graphics.getRGB(color...))
|
||||
g.drawRoundRect(sEdge, sEdge - sHeight/2, sWidth-sEdge*2, sHeight-sEdge*2, sHeight-sEdge*2)
|
||||
|
||||
g.drawRoundRect(EDGE, EDGE - HEIGHT/2, WIDTH-EDGE*2, HEIGHT-EDGE*2, HEIGHT-EDGE*2)
|
||||
s = new createjs.Shape(g)
|
||||
s.z = 100
|
||||
s.baseScale = PROG_BAR_SCALE
|
||||
s.scaleX = 1 / PROG_BAR_SCALE
|
||||
s.scaleY = 1 / PROG_BAR_SCALE
|
||||
s.width = width
|
||||
s.height = height
|
||||
s.regX = (-offset.x + width / 2) * PROG_BAR_SCALE
|
||||
s.regY = (-offset.y) * PROG_BAR_SCALE
|
||||
s.bounds = [0, -HEIGHT/2, WIDTH, HEIGHT]
|
||||
return s
|
||||
|
|
|
@ -6,6 +6,7 @@ SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
|||
ogreMunchkinThangType = new ThangType(require 'test/app/fixtures/ogre-munchkin-m.thang.type')
|
||||
ogreFangriderThangType = new ThangType(require 'test/app/fixtures/ogre-fangrider.thang.type')
|
||||
treeThangType = new ThangType(require 'test/app/fixtures/tree1.thang.type')
|
||||
scaleTestUtils = require './scale-testing-utils'
|
||||
|
||||
describe 'SegmentedSprite', ->
|
||||
segmentedSprite = null
|
||||
|
@ -16,6 +17,10 @@ describe 'SegmentedSprite', ->
|
|||
$('body').append(canvas)
|
||||
stage = new createjs.Stage(canvas[0]) # this is not a SpriteStage because some tests require adding MovieClips
|
||||
stage.addChild(segmentedSprite)
|
||||
scale = 3
|
||||
stage.scaleX = stage.scaleY = scale
|
||||
stage.regX = -300 / scale
|
||||
stage.regY = -200 / scale
|
||||
window.stage = stage
|
||||
|
||||
ticks = 0
|
||||
|
@ -40,8 +45,6 @@ describe 'SegmentedSprite', ->
|
|||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(treeThangType) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, treeThangType, prefix)
|
||||
segmentedSprite.x = 100
|
||||
segmentedSprite.y = 200
|
||||
|
||||
it 'scales rendered containers to the size of the source container', ->
|
||||
# build a movie clip, put it on top of the segmented sprite and make sure
|
||||
|
@ -50,37 +53,15 @@ describe 'SegmentedSprite', ->
|
|||
segmentedSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(treeThangType)
|
||||
container = builder.buildContainerFromStore('Tree_4')
|
||||
container.x = 100
|
||||
container.y = 200
|
||||
container.scaleX = container.scaleY = 0.3
|
||||
container.regX = 59
|
||||
container.regY = 100
|
||||
showMe()
|
||||
stage.addChild(container)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(30, 190, 20)
|
||||
for y in _.range(90, 250, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
g = new createjs.Graphics()
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,64,0.7))
|
||||
g.drawCircle(0, 0, 2)
|
||||
s = new createjs.Shape(g)
|
||||
s.x = x
|
||||
s.y = y
|
||||
stage.addChild(s)
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.98) # not perfect, but pretty close.
|
||||
expect(segmentedSprite.baseScaleX).toBe(0.3)
|
||||
expect(segmentedSprite.baseScaleY).toBe(0.3)
|
||||
# $('canvas').remove()
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-15, -30, 35, 40))
|
||||
expect(hitRate).toBeGreaterThan(0.92)
|
||||
$('canvas').remove()
|
||||
|
||||
it 'scales placeholder containers to the size of the source container', ->
|
||||
# build a movie clip, put it on top of the segmented sprite and make sure
|
||||
|
@ -90,36 +71,14 @@ describe 'SegmentedSprite', ->
|
|||
segmentedSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(treeThangType)
|
||||
container = builder.buildContainerFromStore('Tree_4')
|
||||
container.x = 100
|
||||
container.y = 200
|
||||
container.scaleX = container.scaleY = 0.3
|
||||
container.regX = 59
|
||||
container.regY = 100
|
||||
showMe()
|
||||
stage.addChild(container)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(30, 190, 20)
|
||||
for y in _.range(90, 250, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
g = new createjs.Graphics()
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,64,0.7))
|
||||
g.drawCircle(0, 0, 2)
|
||||
s = new createjs.Shape(g)
|
||||
s.x = x
|
||||
s.y = y
|
||||
stage.addChild(s)
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.84) # the circle is rather out of the tree bounds, so accuracy is low
|
||||
expect(segmentedSprite.baseScaleX).toBe(0.3)
|
||||
expect(segmentedSprite.baseScaleY).toBe(0.3)
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-15, -30, 35, 40))
|
||||
expect(hitRate).toBeGreaterThan(0.73)
|
||||
$('canvas').remove()
|
||||
|
||||
it 'propagates events from the single segment through the segmented sprite', ->
|
||||
|
@ -149,8 +108,6 @@ describe 'SegmentedSprite', ->
|
|||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreMunchkinThangType, null, colorConfig) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, ogreMunchkinThangType, prefix)
|
||||
segmentedSprite.x = 100
|
||||
segmentedSprite.y = 200
|
||||
|
||||
afterEach ->
|
||||
ogreMunchkinThangType.revert()
|
||||
|
@ -193,28 +150,16 @@ describe 'SegmentedSprite', ->
|
|||
segmentedSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(ogreMunchkinThangType)
|
||||
movieClip = builder.buildMovieClip('enemy_small_move_side')
|
||||
movieClip.x = 100
|
||||
movieClip.y = 200
|
||||
movieClip.scaleX = movieClip.scaleY = 0.3
|
||||
movieClip.regX = 285
|
||||
movieClip.regY = 300
|
||||
movieClip.stop()
|
||||
showMe()
|
||||
stage.addChild(movieClip)
|
||||
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(50, 160, 20)
|
||||
for y in _.range(50, 220, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.98) # not perfect, but pretty close.
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-10, -30, 25, 35))
|
||||
expect(hitRate).toBeGreaterThan(0.91)
|
||||
expect(segmentedSprite.baseScaleX).toBe(0.3)
|
||||
expect(segmentedSprite.baseScaleY).toBe(0.3)
|
||||
$('canvas').remove()
|
||||
|
@ -224,28 +169,15 @@ describe 'SegmentedSprite', ->
|
|||
segmentedSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(ogreMunchkinThangType)
|
||||
movieClip = builder.buildMovieClip('enemy_small_move_side')
|
||||
movieClip.x = 100
|
||||
movieClip.y = 200
|
||||
movieClip.scaleX = movieClip.scaleY = 0.3
|
||||
movieClip.regX = 285
|
||||
movieClip.regY = 300
|
||||
movieClip.stop()
|
||||
showMe()
|
||||
stage.addChild(movieClip)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(50, 160, 20)
|
||||
for y in _.range(50, 220, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.96) # not as perfect, but still, close!
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-10, -30, 25, 35))
|
||||
expect(hitRate).toBeGreaterThan(0.96)
|
||||
$('canvas').remove()
|
||||
|
||||
it 'propagates events from the segments through the segmented sprite', ->
|
||||
|
@ -268,8 +200,6 @@ describe 'SegmentedSprite', ->
|
|||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreFangriderThangType, null, colorConfig) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, ogreFangriderThangType, prefix)
|
||||
segmentedSprite.x = 300
|
||||
segmentedSprite.y = 300
|
||||
|
||||
afterEach ->
|
||||
ogreFangriderThangType.revert()
|
||||
|
|
|
@ -5,6 +5,7 @@ SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
|||
ThangType = require 'models/ThangType'
|
||||
ogreMunchkinThangType = new ThangType(require 'test/app/fixtures/ogre-munchkin-m.thang.type')
|
||||
treeThangType = new ThangType(require 'test/app/fixtures/tree1.thang.type')
|
||||
scaleTestUtils = require './scale-testing-utils'
|
||||
|
||||
describe 'SingularSprite', ->
|
||||
singularSprite = null
|
||||
|
@ -15,6 +16,10 @@ describe 'SingularSprite', ->
|
|||
$('body').append(canvas)
|
||||
stage = new createjs.Stage(canvas[0]) # this is not a SpriteStage because some tests require adding MovieClips
|
||||
stage.addChild(singularSprite)
|
||||
scale = 3
|
||||
stage.scaleX = stage.scaleY = scale
|
||||
stage.regX = -300 / scale
|
||||
stage.regY = -200 / scale
|
||||
window.stage = stage
|
||||
|
||||
ticks = 0
|
||||
|
@ -25,6 +30,13 @@ describe 'SingularSprite', ->
|
|||
stage.update()
|
||||
}
|
||||
createjs.Ticker.addEventListener "tick", listener
|
||||
|
||||
afterEach ->
|
||||
g = new createjs.Graphics()
|
||||
g.beginFill(createjs.Graphics.getRGB(64,255,64,0.7))
|
||||
g.drawCircle(0, 0, 1)
|
||||
s = new createjs.Shape(g)
|
||||
stage.addChild(s)
|
||||
|
||||
describe 'with Tree ThangType', ->
|
||||
beforeEach ->
|
||||
|
@ -38,54 +50,27 @@ describe 'SingularSprite', ->
|
|||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(treeThangType) + '.'
|
||||
window.singularSprite = singularSprite = new SingularSprite(sheet, treeThangType, prefix)
|
||||
singularSprite.x = 100
|
||||
singularSprite.y = 200
|
||||
singularSprite.x = 0
|
||||
singularSprite.y = 0
|
||||
|
||||
it 'scales rendered containers to the size of the source container', ->
|
||||
it 'scales rendered containers to the size of the source container, taking into account ThangType scaling', ->
|
||||
# build a movie clip, put it on top of the singular sprite and make sure
|
||||
# they both 'hit' at the same time.
|
||||
|
||||
singularSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(treeThangType)
|
||||
container = builder.buildContainerFromStore('Tree_4')
|
||||
container.x = 100
|
||||
container.y = 200
|
||||
container.regX = 59
|
||||
container.regY = 100
|
||||
container.scaleX = container.scaleY = 0.3
|
||||
showMe()
|
||||
stage.addChild(container)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(30, 190, 20)
|
||||
for y in _.range(90, 250, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
g = new createjs.Graphics()
|
||||
if hasSprite and hasShape
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,164,0.7))
|
||||
else if hasSprite
|
||||
g.beginFill(createjs.Graphics.getRGB(64,164,64,0.7))
|
||||
else
|
||||
g.beginFill(createjs.Graphics.getRGB(164,64,64,0.7))
|
||||
g.drawCircle(0, 0, 2)
|
||||
s = new createjs.Shape(g)
|
||||
s.x = x
|
||||
s.y = y
|
||||
stage.addChild(s)
|
||||
else
|
||||
hits += 1
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-15, -30, 35, 40))
|
||||
expect(hitRate).toBeGreaterThan(0.92)
|
||||
# $('canvas').remove()
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.98)
|
||||
expect(singularSprite.baseScaleX).toBeCloseTo(1.1111)
|
||||
expect(singularSprite.baseScaleY).toBeCloseTo(1.1111)
|
||||
$('canvas').remove()
|
||||
|
||||
it 'scales placeholder containers to the size of the source container', ->
|
||||
it 'scales placeholder containers to the size of the source container, taking into account ThangType scaling', ->
|
||||
# build a movie clip, put it on top of the singular sprite and make sure
|
||||
# they both 'hit' at the same time.
|
||||
|
||||
|
@ -93,39 +78,14 @@ describe 'SingularSprite', ->
|
|||
singularSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(treeThangType)
|
||||
container = builder.buildContainerFromStore('Tree_4')
|
||||
container.x = 100
|
||||
container.y = 200
|
||||
container.regX = 59
|
||||
container.regY = 100
|
||||
container.scaleX = container.scaleY = 0.3
|
||||
showMe()
|
||||
stage.addChild(container)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(30, 190, 20)
|
||||
for y in _.range(90, 250, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
g = new createjs.Graphics()
|
||||
if hasSprite and hasShape
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,164,0.7))
|
||||
else if hasSprite
|
||||
g.beginFill(createjs.Graphics.getRGB(64,164,64,0.7))
|
||||
else
|
||||
g.beginFill(createjs.Graphics.getRGB(164,64,64,0.7))
|
||||
g.drawCircle(0, 0, 2)
|
||||
s = new createjs.Shape(g)
|
||||
s.x = x
|
||||
s.y = y
|
||||
stage.addChild(s)
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.84)
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-15, -30, 35, 40))
|
||||
expect(hitRate).toBeGreaterThan(0.73)
|
||||
# $('canvas').remove()
|
||||
|
||||
describe 'with Ogre Munchkin ThangType', ->
|
||||
|
@ -143,8 +103,6 @@ describe 'SingularSprite', ->
|
|||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreMunchkinThangType, null, colorConfig) + '.'
|
||||
window.singularSprite = singularSprite = new SingularSprite(sheet, ogreMunchkinThangType, prefix)
|
||||
singularSprite.x = 100
|
||||
singularSprite.y = 200
|
||||
|
||||
afterEach ->
|
||||
ogreMunchkinThangType.revert()
|
||||
|
@ -153,38 +111,25 @@ describe 'SingularSprite', ->
|
|||
singularSprite.gotoAndPlay('move_fore')
|
||||
singularSprite.gotoAndStop('attack')
|
||||
|
||||
it 'scales rendered animations like a MovieClip', ->
|
||||
it 'scales rendered animations like a MovieClip, taking into account ThangType scaling', ->
|
||||
# build a movie clip, put it on top of the segmented sprite and make sure
|
||||
# they both 'hit' at the same time.
|
||||
|
||||
singularSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(ogreMunchkinThangType)
|
||||
movieClip = builder.buildMovieClip('enemy_small_move_side')
|
||||
movieClip.x = 100
|
||||
movieClip.y = 200
|
||||
movieClip.scaleX = movieClip.scaleY = 0.3
|
||||
movieClip.regX = 285
|
||||
movieClip.regY = 300
|
||||
movieClip.stop()
|
||||
showMe()
|
||||
stage.addChild(movieClip)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(50, 160, 20)
|
||||
for y in _.range(50, 220, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.98) # not perfect, but pretty close.
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-10, -30, 25, 35))
|
||||
expect(hitRate).toBeGreaterThan(0.91)
|
||||
$('canvas').remove()
|
||||
|
||||
it 'scales placeholder animations like a MovieClip', ->
|
||||
it 'scales placeholder animations like a MovieClip, taking into account ThangType scaling', ->
|
||||
# build a movie clip, put it on top of the segmented sprite and make sure
|
||||
# they both 'hit' at the same time.
|
||||
|
||||
|
@ -192,26 +137,13 @@ describe 'SingularSprite', ->
|
|||
singularSprite.gotoAndStop('idle')
|
||||
builder = new SpriteBuilder(ogreMunchkinThangType)
|
||||
movieClip = builder.buildMovieClip('enemy_small_move_side')
|
||||
movieClip.x = 100
|
||||
movieClip.y = 200
|
||||
movieClip.scaleX = movieClip.scaleY = 0.3
|
||||
movieClip.regX = 285
|
||||
movieClip.regY = 300
|
||||
movieClip.stop()
|
||||
showMe()
|
||||
stage.addChild(movieClip)
|
||||
stage.update()
|
||||
t = new Date()
|
||||
tests = hits = 0
|
||||
for x in _.range(50, 160, 20)
|
||||
for y in _.range(50, 220, 20)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
if objects.length
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits+= 1 if hasSprite and hasShape
|
||||
else
|
||||
hits += 1
|
||||
|
||||
expect(hits / tests).toBeGreaterThan(0.87) # not perfect, but pretty close.
|
||||
hitRate = scaleTestUtils.hitTest(stage, new createjs.Rectangle(-10, -30, 25, 35))
|
||||
expect(hitRate).toBeGreaterThan(0.71)
|
||||
$('canvas').remove()
|
|
@ -79,10 +79,10 @@ describe 'SpriteBoss', ->
|
|||
# Now make the world a little more complicated.
|
||||
world.thangs = world.thangs.concat [
|
||||
# four cardinal ogres, to test movement rotation and placement around a center point.
|
||||
{id: 'Ogre N', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5 }
|
||||
{id: 'Ogre W', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5 }
|
||||
{id: 'Ogre E', spriteName: 'Segmented Munchkin', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5 }
|
||||
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:-8}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Ogre N', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre W', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-8, y:0}, action: 'move', health: 8, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre E', spriteName: 'Segmented Munchkin', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:-8}, action: 'move', health: 2, maxHealth: 10, rotation: Math.PI/2, acts: true, hudProperties: ['health'] }
|
||||
|
||||
# Set ogres side by side with different render strategies
|
||||
{id: 'Singular Ogre', spriteName: 'Singular Munchkin', exists: true, pos: {x:-10, y:-8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, alpha: 0.5 }
|
||||
|
@ -124,7 +124,6 @@ describe 'SpriteBoss', ->
|
|||
handleEvent: ->
|
||||
return if ticks >= 100
|
||||
ticks += 1
|
||||
console.log 'update'
|
||||
if ticks % 20 is 0
|
||||
spriteBoss.update(true)
|
||||
stage.update()
|
||||
|
|
23
test/app/lib/surface/scale-testing-utils.coffee
Normal file
23
test/app/lib/surface/scale-testing-utils.coffee
Normal file
|
@ -0,0 +1,23 @@
|
|||
module.exports.hitTest = (stage, bounds) ->
|
||||
tests = hits = 0
|
||||
for x in _.range(bounds.x, bounds.x + bounds.width, 5)
|
||||
for y in _.range(bounds.y, bounds.y + bounds.height, 5)
|
||||
tests += 1
|
||||
objects = stage.getObjectsUnderPoint(x, y)
|
||||
hasSprite = _.any objects, (o) -> o instanceof createjs.Sprite
|
||||
hasShape = _.any objects, (o) -> o instanceof createjs.Shape
|
||||
hits += 1 if (hasSprite and hasShape) or not (hasSprite or hasShape)
|
||||
g = new createjs.Graphics()
|
||||
if hasSprite and hasShape
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,255,0.7))
|
||||
else if not (hasSprite or hasShape)
|
||||
g.beginFill(createjs.Graphics.getRGB(64,64,64,0.7))
|
||||
else
|
||||
g.beginFill(createjs.Graphics.getRGB(255,64,64,0.7))
|
||||
g.drawCircle(0, 0, 2)
|
||||
s = new createjs.Shape(g)
|
||||
s.x = x
|
||||
s.y = y
|
||||
stage.addChild(s)
|
||||
return hits/tests
|
||||
|
Loading…
Reference in a new issue