codecombat/app/lib/surface/Letterbox.coffee

38 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
module.exports = class Letterbox extends createjs.Container
subscriptions:
'level-set-letterbox': 'onSetLetterbox'
constructor: (options) ->
super()
@initialize()
@canvasWidth = options.canvasWidth
@canvasHeight = options.canvasHeight
2014-06-30 22:16:26 -04:00
console.error 'Letterbox needs canvasWidth/Height.' unless @canvasWidth and @canvasHeight
2014-01-03 13:32:13 -05:00
@build()
Backbone.Mediator.subscribe(channel, @[func], @) for channel, func of @subscriptions
build: ->
@mouseEnabled = @mouseChildren = false
@matteHeight = 0.10 * @canvasHeight
@upperMatte = new createjs.Shape()
2014-06-30 22:16:26 -04:00
@upperMatte.graphics.beginFill('black').rect(0, 0, @canvasWidth, @matteHeight)
2014-01-03 13:32:13 -05:00
@lowerMatte = @upperMatte.clone()
@upperMatte.x = @lowerMatte.x = 0
@upperMatte.y = -@matteHeight
@lowerMatte.y = @canvasHeight
@addChild @upperMatte, @lowerMatte
onSetLetterbox: (e) ->
T = createjs.Tween
T.removeTweens @upperMatte
T.removeTweens @lowerMatte
upperY = if e.on then 0 else -@matteHeight
lowerY = if e.on then @canvasHeight - @matteHeight else @canvasHeight
interval = 700
ease = createjs.Ease.cubicOut
T.get(@upperMatte).to({y: upperY}, interval, ease)
T.get(@lowerMatte).to({y: lowerY}, interval, ease)
destroy: ->
Backbone.Mediator.unsubscribe(channel, @[func], @) for channel, func of @subscriptions