2012年12月21日 星期五

Strling將2個Juggler與Tween組合,並且快速執行個體

 
package demo5_juggler_tween_delayedCall 
{
 import starling.animation.Juggler;
 import starling.animation.Transitions;
 import starling.animation.Tween;
 import starling.core.Starling;
 import starling.display.Button;
 import starling.display.Image;
 import starling.display.Sprite;
 import starling.events.Event;
 import starling.textures.Texture;
 
 /**
  * ...
  * @author RayCheng
  */
 public class Demo5Page extends Sprite 
 {
  [Embed(source = "../../bin/btn0.png")]
  private static const BtnBimp:Class;
  [Embed(source = "../../bin/btn1.png")]
  private static const BtnDownBimp:Class;
  [Embed(source = "../../bin/starling_front.png")]
  private static const ImgItem:Class;
  
  private var _container:Sprite;
  private var _btn:Button;
  private var _imgItem:Image;
  
  public function Demo5Page() 
  {
   this.addEventListener(Event.ADDED_TO_STAGE, init);
  }
  
  private function init(e:Event):void 
  {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   create();
  }
  
  private function create():void 
  {
   //--設定按鈕
   _btn = new Button(Texture.fromBitmap(new BtnBimp()), "TweenTest", Texture.fromBitmap(new BtnDownBimp));
   _btn.x = stage.stageWidth - _btn.width >> 1;
   _btn.y = stage.stageHeight - _btn.height;
   addChild(_btn)
   
   _btn.addEventListener(Event.TRIGGERED, onBtnTriggeredHandler);
   
  }
  
  private function onBtnTriggeredHandler(e:Event):void 
  {
   //--設定表演item
   _container = new Sprite();
   addChild(_container);
   
   _imgItem = new Image(Texture.fromBitmap(new ImgItem()));
   _imgItem.pivotX = _imgItem.width >> 1;
   _imgItem.pivotY = _imgItem.height >> 1;
   _container.addChild(_imgItem);
   _container.x = stage.stageWidth >> 1;
   _container.y = stage.stageHeight +_container.height / 2;
   
   var $tween:Tween = new Tween(_container, .5, Transitions.EASE_IN);
   $tween.animate("x", Math.random()*stage.stageWidth);
   $tween.animate("y", 150);
   $tween.onComplete = whenActionUp;
   $tween.onCompleteArgs=[_container]
   Starling.current.juggler.add($tween);
   
  }
  
  private function whenActionUp(pTarget:Sprite):void 
  {
   var $tween:Tween = new Tween(pTarget, .5, Transitions.EASE_IN_OUT);
   $tween.animate("y", stage.stageHeight +_container.height / 2);
   $tween.scaleTo(.5);
   $tween.onComplete = whenActionDowne;
   $tween.onCompleteArgs = [pTarget];
   Starling.current.juggler.add($tween);
  }
  
  private function whenActionDowne(pTarget:Sprite):void 
  {
   pTarget.dispose();
   removeChild(pTarget);
   trace(this.numChildren)
  }
  
 }

}

沒有留言:

張貼留言

我的留言版