Skip to content

Instantly share code, notes, and snippets.

@jdoig
Last active December 13, 2015 20:38
Show Gist options
  • Save jdoig/4970999 to your computer and use it in GitHub Desktop.
Save jdoig/4970999 to your computer and use it in GitHub Desktop.
Coffeescript game{closure} trail animation example
`import ui.View as View`
`import animate`
toColor = (x) -> (x % 255).toString(16)
class Trail extends GC.Application
createTrail: (pt) ->
opts = merge(pt, {superview: GC.app.view})
new TrailBox(pt, opts)
initUI: ->
@style.backgroundColor = '#FFFFFF'
@view.on('InputMove',(evt,pt) -> @.createTrail(pt))
launchUI: -> #disable splash screen
class TrailBox extends View
init: (opts) ->
colorZ = toColor(opts.x + opts.y)
colorX = toColor(opts.x)
colorY = toColor(opts.y)
options = merge(opts, {
backgroundColor: '#'+ colorZ + colorX + colorY
opacity: 0.8
anchorX: 1.5
anchorY: 1.5
width: 3
height: 3
r: 0 })
super options
fadeAnimation = {
opacity: 0
x: opts.x - 15
y: opts.y - 15
anchorX: 15
anchorY: 15
width: 30
height: 30
r: Math.PI * 4}
animate(@).now(fadeAnimation, 1500).then(@.remove())
remove: ->
=> @.removeFromSuperview()
`exports = Trail`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment