Made paths more visible, because I couldn't see them.

This commit is contained in:
Nick Winter 2014-11-18 18:13:59 -08:00
parent e93de815c2
commit 666334b28c

View file

@ -1,18 +1,18 @@
PAST_PATH_ALPHA = 0.75 PAST_PATH_ALPHA = 0.75
PAST_PATH_WIDTH = 5 PAST_PATH_WIDTH = 5
FUTURE_PATH_ALPHA = 0.4 FUTURE_PATH_ALPHA = 0.75
FUTURE_PATH_WIDTH = 2 FUTURE_PATH_WIDTH = 4
TARGET_ALPHA = 1 TARGET_ALPHA = 1
TARGET_WIDTH = 10 TARGET_WIDTH = 10
FUTURE_PATH_INTERVAL_DIVISOR = 4 FUTURE_PATH_INTERVAL_DIVISOR = 4
PAST_PATH_INTERVAL_DIVISOR = 2 PAST_PATH_INTERVAL_DIVISOR = 2
Camera = require './Camera' Camera = require './Camera'
CocoClass = require 'lib/CocoClass' CocoClass = require 'lib/CocoClass'
module.exports = class TrailMaster extends CocoClass module.exports = class TrailMaster extends CocoClass
world: null world: null
constructor: (@camera, @layerAdapter) -> constructor: (@camera, @layerAdapter) ->
super() super()
@tweenedSprites = [] @tweenedSprites = []
@ -31,24 +31,25 @@ module.exports = class TrailMaster extends CocoClass
pathDisplayObject.addChild @createTargets() pathDisplayObject.addChild @createTargets()
@generatingPaths = false @generatingPaths = false
return pathDisplayObject return pathDisplayObject
cleanUp: -> cleanUp: ->
createjs.Tween.removeTweens(sprite) for sprite in @tweenedSprites createjs.Tween.removeTweens(sprite) for sprite in @tweenedSprites
@tweenedSprites = [] @tweenedSprites = []
@tweens = [] @tweens = []
createGraphics: -> createGraphics: ->
@targetDotKey = @cachePathDot(TARGET_WIDTH, @colorForThang(@thang.team, TARGET_ALPHA)) @targetDotKey = @cachePathDot(TARGET_WIDTH, @colorForThang(@thang.team, TARGET_ALPHA), [0, 0, 0, 1])
@pastDotKey = @cachePathDot(PAST_PATH_WIDTH, @colorForThang(@thang.team, PAST_PATH_ALPHA)) @pastDotKey = @cachePathDot(PAST_PATH_WIDTH, @colorForThang(@thang.team, PAST_PATH_ALPHA), [0, 0, 0, 1])
@futureDotKey = @cachePathDot(FUTURE_PATH_WIDTH, @colorForThang(@thang.team, FUTURE_PATH_ALPHA)) @futureDotKey = @cachePathDot(FUTURE_PATH_WIDTH, [255, 255, 255, FUTURE_PATH_ALPHA], @colorForThang(@thang.team, 1))
cachePathDot: (width, color) -> cachePathDot: (width, fillColor, strokeColor) ->
key = "path-dot-#{width}-#{color}" key = "path-dot-#{width}-#{fillColor}-#{strokeColor}"
color = createjs.Graphics.getRGB(color...) fillColor = createjs.Graphics.getRGB(fillColor...)
strokeColor = createjs.Graphics.getRGB(strokeColor...)
unless key in @layerAdapter.spriteSheet.getAnimations() unless key in @layerAdapter.spriteSheet.getAnimations()
circle = new createjs.Shape() circle = new createjs.Shape()
radius = width/2 radius = width/2
circle.graphics.setStrokeStyle(width/5).beginFill(color).beginStroke('#000000').drawCircle(0, 0, radius) circle.graphics.setStrokeStyle(width/5).beginFill(fillColor).beginStroke(strokeColor).drawCircle(0, 0, radius)
@layerAdapter.addCustomGraphic(key, circle, [-radius*1.5, -radius*1.5, radius*3, radius*3]) @layerAdapter.addCustomGraphic(key, circle, [-radius*1.5, -radius*1.5, radius*3, radius*3])
return key return key
@ -58,7 +59,7 @@ module.exports = class TrailMaster extends CocoClass
rgb = [0, 0, 255] if team is 'ogres' rgb = [0, 0, 255] if team is 'ogres'
rgb.push(alpha) rgb.push(alpha)
return rgb return rgb
createPastPath: -> createPastPath: ->
return unless points = @world.pointsForThang @thang.id, @camera return unless points = @world.pointsForThang @thang.id, @camera
interval = Math.max(1, parseInt(@world.frameRate / PAST_PATH_INTERVAL_DIVISOR)) interval = Math.max(1, parseInt(@world.frameRate / PAST_PATH_INTERVAL_DIVISOR))
@ -85,13 +86,13 @@ module.exports = class TrailMaster extends CocoClass
sprite.y = sup.y sprite.y = sup.y
container.addChild(sprite) container.addChild(sprite)
return container return container
createPath: (points, options={}) -> createPath: (points, options={}) ->
options = options or {} options = options or {}
interval = options.interval or 8 interval = options.interval or 8
key = options.frameKey or @pastDotKey key = options.frameKey or @pastDotKey
container = new createjs.SpriteContainer(@layerAdapter.spriteSheet) container = new createjs.SpriteContainer(@layerAdapter.spriteSheet)
for x, i in points by interval * 2 for x, i in points by interval * 2
y = points[i + 1] y = points[i + 1]
sprite = new createjs.Sprite(@layerAdapter.spriteSheet) sprite = new createjs.Sprite(@layerAdapter.spriteSheet)
@ -106,16 +107,16 @@ module.exports = class TrailMaster extends CocoClass
@tweenedSprites.push lastSprite @tweenedSprites.push lastSprite
@tweens.push tween @tweens.push tween
lastSprite = sprite lastSprite = sprite
@logged = true @logged = true
container container
play: -> play: ->
tween.setPaused(false) for tween in @tweens tween.setPaused(false) for tween in @tweens
stop: -> stop: ->
tween.setPaused(true) for tween in @tweens tween.setPaused(true) for tween in @tweens
destroy: -> destroy: ->
@cleanUp() @cleanUp()
super() super()