topical media & game development

talk show tell print

mobile-graphic-easel-tutorials-HitTest-localToLocal.htm / htm



  <!DOCTYPE html>
  <html>
  <head>
          <title>EaselJS demo: localToLocal</title>
          <link href="../shared/demo.css" rel="stylesheet" type="text/css">
          <script src="../../lib/easeljs-0.6.0.min.js"></script>
          <script>
                  var stage, arm;
                  function init() {
                          stage = new createjs.Stage("demoCanvas");
                          
                          target = stage.addChild(new createjs.Shape());
                          target.graphics.beginFill("red").drawCircle(0,0,45)
                                  .beginFill("white").drawCircle(0,0,30)
                                  .beginFill("red").drawCircle(0,0,15);
                          target.x = 100;
                          target.y = 180;
                          
                          arm = stage.addChild(new createjs.Shape());
                          arm.graphics.beginFill("black").drawRect(-2,-2,100,4)
                                  .beginFill("blue").drawCircle(100,0,8);
                          arm.x = 180;
                          arm.y = 100;
                          
                          createjs.Ticker.addEventListener("tick", tick);
                  }
                  
                  function tick(event) {
                          arm.rotation += 5;
                          
                          target.alpha = 0.2;
                          var pt = arm.localToLocal(100,0,target);
                          if (target.hitTest(pt.x, pt.y)) { target.alpha = 1; }
                          
                          stage.update(event);
                  }
          </script>
  </head>
  <body onLoad="init();">
          <canvas id="demoCanvas" width="300" height="300">
                  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.