vendredi 1 juin 2012

HTML 5 - EaselJs : Like flash Syntax (animation)


  1. var stage;  
  2. var logo;  
  3. var myText;  
  4.   
  5.    init();  
  6.   
  7.   
  8.   
  9. function init(){  
  10.   
  11.  stage = new Stage(document.getElementById("container"));  
  12.        
  13.  logo = new Bitmap("http://jsrun.it/assets/3/6/8/m/368mt.png");  
  14.    
  15.  logo.shadow = new Shadow("#4d4d4d", 2, 2, 2);  
  16.    
  17.  myText = new Text('Happy new year 2012''Bold 18px Arial''#000');  
  18.  myText.x = 0;  
  19.  myText.y = 0;  
  20.    
  21.  stage.addChild(myText);  
  22.    
  23.  Tween.get(myText).to({x:150},6000);  
  24.  Tween.get(myText).to({y:250},6000);  
  25.    
  26.    
  27.  myText.scaleX = 1.2;  
  28.  myText.scaleY = 1.2;  
  29.   
  30.  stage.addChild(logo);  
  31.   
  32.  var g = new Graphics();  
  33.  g.beginFill("#d2e9ff");  
  34.  g.drawCircle(0,0,3);  
  35.  //dd  
  36.  Ticker.setFPS(80);  
  37.  Ticker.addListener(window);  
  38. }  
  39. function tick(){  
  40.  myText.rotation  += 1;  
  41.  var temp = logo.clone();  
  42.  stage.addChild(temp);  
  43.  logo.rotation +=5;  
  44.  logo.x +=(stage.mouseX - logo.x) *0.1;  
  45.  logo.y +=(stage.mouseY - logo.y) *0.1;  
  46.         setTimeout(function(){stage.removeChild(temp);},700);  
  47.  stage.update();  
  48.   
  49.  }  
  50. <script src="http://mgraph-communication.com/easel.js"></script>  
  51. <script src="http://tweenjs.com/src/tweenjs/Tween.js"></script>  
  52. <script src="http://tweenjs.com/src/tweenjs/Ease.js"></script>  
  53.       
  54. <canvas id="container" width="460" height="400"></canvas>