mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-28 23:13:59 -04:00
Set up CocoSprites to have text appear overhead based on events coming from the ShowsText component.
This commit is contained in:
parent
4be67113be
commit
f99a95768e
1 changed files with 30 additions and 4 deletions
|
@ -69,7 +69,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@marks = {}
|
@marks = {}
|
||||||
@labels = {}
|
@labels = {}
|
||||||
@ranges = []
|
@ranges = []
|
||||||
@handledAoEs = {}
|
@handledDisplayEvents = {}
|
||||||
@age = 0
|
@age = 0
|
||||||
@scaleFactor = @targetScaleFactor = 1
|
@scaleFactor = @targetScaleFactor = 1
|
||||||
if @thangType.isFullyLoaded()
|
if @thangType.isFullyLoaded()
|
||||||
|
@ -213,6 +213,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@updatePosition()
|
@updatePosition()
|
||||||
frameChanged = frameChanged or @targetScaleFactor isnt @scaleFactor
|
frameChanged = frameChanged or @targetScaleFactor isnt @scaleFactor
|
||||||
if frameChanged
|
if frameChanged
|
||||||
|
@handledDisplayEvents = {}
|
||||||
@updateScale() # must happen before rotation
|
@updateScale() # must happen before rotation
|
||||||
@updateAlpha()
|
@updateAlpha()
|
||||||
@updateRotation()
|
@updateRotation()
|
||||||
|
@ -220,6 +221,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@updateStats()
|
@updateStats()
|
||||||
@updateGold()
|
@updateGold()
|
||||||
@showAreaOfEffects()
|
@showAreaOfEffects()
|
||||||
|
@showTextEvents()
|
||||||
@updateHealthBar()
|
@updateHealthBar()
|
||||||
@updateMarks()
|
@updateMarks()
|
||||||
@updateLabels()
|
@updateLabels()
|
||||||
|
@ -228,9 +230,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
return unless @thang?.currentEvents
|
return unless @thang?.currentEvents
|
||||||
for event in @thang.currentEvents
|
for event in @thang.currentEvents
|
||||||
continue unless event.startsWith 'aoe-'
|
continue unless event.startsWith 'aoe-'
|
||||||
continue if @handledAoEs[event]
|
continue if @handledDisplayEvents[event]
|
||||||
|
|
||||||
@handledAoEs[event] = true
|
@handledDisplayEvents[event] = true
|
||||||
args = JSON.parse(event[4...])
|
args = JSON.parse(event[4...])
|
||||||
pos = @options.camera.worldToSurface {x:args[0], y:args[1]}
|
pos = @options.camera.worldToSurface {x:args[0], y:args[1]}
|
||||||
circle = new createjs.Shape()
|
circle = new createjs.Shape()
|
||||||
|
@ -248,7 +250,31 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
.call =>
|
.call =>
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
@options.groundLayer.removeChild circle
|
@options.groundLayer.removeChild circle
|
||||||
delete @handledAoEs[event]
|
delete @handledDisplayEvents[event]
|
||||||
|
|
||||||
|
showTextEvents: ->
|
||||||
|
return unless @thang?.currentEvents
|
||||||
|
for event in @thang.currentEvents
|
||||||
|
continue unless event.startsWith 'text-'
|
||||||
|
continue if @handledDisplayEvents[event]
|
||||||
|
@handledDisplayEvents[event] = true
|
||||||
|
options = JSON.parse(event[5...])
|
||||||
|
label = new createjs.Text options.text, "bold #{options.size or 16}px Arial", options.color or '#FFF'
|
||||||
|
label.shadow = new createjs.Shadow '#000', 0, 0, 2
|
||||||
|
offset = @getOffset 'aboveHead'
|
||||||
|
[label.x, label.y] = [@imageObject.x + offset.x - label.getMeasuredWidth() / 2, @imageObject.y + offset.y]
|
||||||
|
@options.floatingLayer.addChild label
|
||||||
|
window.labels ?= []
|
||||||
|
window.labels.push label
|
||||||
|
label.alpha = 0
|
||||||
|
createjs.Tween.get(label)
|
||||||
|
.to({y:label.y-2, alpha:1}, 200, createjs.Ease.linear)
|
||||||
|
.to({y:label.y-12}, 1000, createjs.Ease.linear)
|
||||||
|
.to({y:label.y-22, alpha:0}, 1000, createjs.Ease.linear)
|
||||||
|
.call =>
|
||||||
|
return if @destroyed
|
||||||
|
@options.floatingLayer.removeChild label
|
||||||
|
|
||||||
|
|
||||||
cache: ->
|
cache: ->
|
||||||
bounds = @imageObject.getBounds()
|
bounds = @imageObject.getBounds()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue