topical media & game development

talk show tell print

mobile-graphic-easel-tutorials-Animation-and-Ticker-simple.htm / htm



  <!DOCTYPE html>
  <html>
  <head>
          <title>EaselJS demo: Simple animation</title>
          <link href="../shared/demo.css" rel="stylesheet" type="text/css">
          <script src="../../lib/easeljs-0.6.0.min.js"></script>
          <script>
                  
                  var stage, circle;
                  function init() {
                          stage = new createjs.Stage("demoCanvas");
                          
                          circle = new createjs.Shape();
                          circle.graphics.beginFill("red").drawCircle(0, 0, 40);
                          circle.y = 50;
                          stage.addChild(circle);
                          
                          createjs.Ticker.addEventListener("tick", tick);
                          createjs.Ticker.setFPS(30);
                  }
                  
                  function tick(event) {
                          circle.x = circle.x + 5;
                          if (circle.x > stage.canvas.width) { circle.x = 0; }
                          stage.update(event); // important!!
                  }
          </script>
  </head>
  <body onLoad="init();">
          <canvas id="demoCanvas" width="500" height="100">
                  alternate content
          </canvas>
  </body>
  </html>


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.