Gave the health bar a border, made it a little more high res.

This commit is contained in:
Scott Erickson 2014-03-07 17:37:11 -08:00
parent 8fa9c9c410
commit fe2ced1a67
2 changed files with 15 additions and 3 deletions

View file

@ -328,7 +328,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
return if @thang.health is @lastHealth
@lastHealth = @thang.health
healthPct = Math.max(@thang.health / @thang.maxHealth, 0)
bar.scaleX = healthPct
bar.scaleX = healthPct / bar.baseScale
healthOffset = @getOffset 'aboveHead'
[bar.x, bar.y] = [healthOffset.x - bar.width / 2, healthOffset.y]
@ -357,7 +357,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
bar = @healthBar = createProgressBar(healthColor, healthOffset.y)
bar.x = healthOffset.x - bar.width / 2
bar.name = 'health bar'
bar.cache 0, -bar.height / 2, bar.width, bar.height
bar.cache 0, -bar.height * bar.baseScale / 2, bar.width * bar.baseScale, bar.height * bar.baseScale
@displayObject.addChild bar
getActionProp: (prop, subProp, def=null) ->

View file

@ -1,16 +1,28 @@
PROG_BAR_WIDTH = 20
PROG_BAR_HEIGHT = 2
PROG_BAR_SCALE = 2.5
EDGE_SIZE = 0.3
module.exports.createProgressBar = createProgressBar = (color, y, width=PROG_BAR_WIDTH, height=PROG_BAR_HEIGHT) ->
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.beginFill(createjs.Graphics.getRGB(color...))
g.drawRoundRect(0, -1, width, height, height)
g.drawRoundRect(sEdge, sEdge - sHeight/2, sWidth-sEdge*2, sHeight-sEdge*2, sHeight-sEdge*2)
s = new createjs.Shape(g)
s.x = -width / 2
s.y = y
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
return s