Last active
December 13, 2015 20:38
-
-
Save jdoig/4970999 to your computer and use it in GitHub Desktop.
Coffeescript game{closure} trail animation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`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