I started a new job a couple of weeks back with Blake Education making kids educational games. They have a nice framework under development for their HTML5 game development that automagically looks after a lot of things, like tying together Coffeescript, EaselJS, and Greensock. It’s nice working with their framework, but since I hadn’t used any of these techs, I wanted to start exploring them outside the framework to get a better understanding of they all play together.
It took a little bit of noodling to understand how they fit together. For future reference, here’s some simple code that has all three playing nice.
HTML
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Easel 101</title> <style> body { margin: 0px; padding: 10px; } #canvas { background: #CCC; } </style> <script src="./js/lib/easeljs.js"></script> <script src="./js/lib/TweenMax.js"></script> <script src="./js/easel01.js"></script> </head> <body onLoad="init();"> <canvas id="canvas" width="700" height="40"></canvas> </body> </html> |
Coffeescript with EaselJS and Greensock
class window.Test constructor: -> @stage = new createjs.Stage(document.getElementById 'canvas') @circle = {x: 10, y: 20, r: 10} TweenLite.to(@circle, 2, {delay: 2, x: 500, y: 20, ease: Elastic.easeOut}) createjs.Ticker.addListener @ drawCircle: => circle = new createjs.Shape() circle.graphics.beginFill('#606').drawCircle(@circle.x, @circle.y, @circle.r) @stage.addChild(circle) tick: -> @stage.removeAllChildren() @drawCircle() @stage.update() window.init = -> new Test() |
{ 0 comments }
