Tweensy - repeatType

Tweensyはアニメーションをリピートすることができる。この辺からいよいよTweenerにはない独自機能な香り。

TweensyTimelineオブジェクトのrepeatTypeにリピートの種類を設定することができる。項目は

  • TweensyTimeline.NONE - デフォルト値。リピートしない。
  • TweensyTimeline.REPLAY - 終点に到達後、すぐに始点に戻って終点へアニメーションする。
  • TweensyTimeline.YOYO - 終点に到達後、delayを挟んで始点へアニメーションする。
  • TweensyTimeline.LOOP - 終点に到達後、すぐに始点へアニメーションし、その後delayする。
の4種類。TweensyTimeline.NONEはリピートしないので、実質3種類のリピートが用意されている。YOYOとLOOPはdelayするタイミングが折り返し前か後かの差がある。delay入れなかったら両者は同じ挙動をする。

TestTweensy_6.swf

  • ActionScript
  • TestTweensy_6.as
  • Source
package  {
	import com.flashdynamix.motion.Tweensy;
	import com.flashdynamix.motion.TweensyTimeline;
	import fl.motion.easing.Quadratic;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	[SWF(backgroundColor = 0x000000, width = 600, height = 200, frameRate = 30)]
	public class TestTweensy_6 extends Sprite {

		private var _boxes:Array;

		public function TestTweensy_6() {
			initInstances();

			startTweensy();
		}

		private function initInstances():void {
			var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);
			var graphics:Graphics = graphics;
			graphics.lineStyle(1, 0xffffff, 0.5);

			_boxes = [];
			var strings:Array = [
				'NONE',
				'REPLAY',
				'YOYO',
				'LOOP'
			];
			var i:int, j:int, y:Number, box:Sprite, textField:TextField;
			for (i = 0; i < strings.length; i ++) {
				y = 60 + 15 * i;

				box = createBox();
				box.x = 100;
				box.y = y;
				_boxes[i] = box;

				addChild(box);

				graphics.moveTo(100, y);
				graphics.lineTo(500, y);
				for (j = 0; j < 2; j ++) {
					textFormat.align = (j == 0)? TextFormatAlign.RIGHT: TextFormatAlign.LEFT;
					textField = new TextField();
					textField.defaultTextFormat = textFormat;
					textField.text = strings[i];
					textField.x = (j == 0)? 10: 510;
					textField.y = y - 8;
					textField.width = 80;
					addChild(textField);
				}
			}
		}

		private function createBox():Sprite {
			var box:Sprite = new Sprite();
			var graphics:Graphics = box.graphics;

			graphics.beginFill(0x0099cc);
			graphics.drawRect(-5, -5, 10, 10);
			graphics.endFill();

			return box;
		}

		private function startTweensy():void{
			var repeatTypes:Array = [
				TweensyTimeline.NONE,
				TweensyTimeline.REPLAY,
				TweensyTimeline.YOYO,
				TweensyTimeline.LOOP
			];

			var i:int, box:Sprite, timeline:TweensyTimeline;
			for (i = 0; i < _boxes.length; i ++) {
				box = _boxes[i];
				timeline = Tweensy.to(box, { x: 500 }, 3, Quadratic.easeOut, 1);
				timeline.repeatType = repeatTypes[i];
			}
		}


	}

}
  1. package  {
  2.     import com.flashdynamix.motion.Tweensy;
  3.     import com.flashdynamix.motion.TweensyTimeline;
  4.     import fl.motion.easing.Quadratic;
  5.     import flash.display.Graphics;
  6.     import flash.display.Sprite;
  7.     import flash.text.TextField;
  8.     import flash.text.TextFieldAutoSize;
  9.     import flash.text.TextFormat;
  10.     import flash.text.TextFormatAlign;
  11.  
  12.     [SWF(backgroundColor = 0x000000, width = 600, height = 200, frameRate = 30)]
  13.     public class TestTweensy_6 extends Sprite {
  14.  
  15.         private var _boxes:Array;
  16.  
  17.         public function TestTweensy_6() {
  18.             initInstances();
  19.  
  20.             startTweensy();
  21.         }
  22.  
  23.         private function initInstances():void {
  24.             var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);
  25.             var graphics:Graphics = graphics;
  26.             graphics.lineStyle(1, 0xffffff, 0.5);
  27.  
  28.             _boxes = [];
  29.             var strings:Array = [
  30.                 'NONE',
  31.                 'REPLAY',
  32.                 'YOYO',
  33.                 'LOOP'
  34.             ];
  35.             var i:int, j:int, y:Number, box:Sprite, textField:TextField;
  36.             for (i = 0; i < strings.length; i ++) {
  37.                 y = 60 + 15 * i;
  38.  
  39.                 box = createBox();
  40.                 box.x = 100;
  41.                 box.y = y;
  42.                 _boxes[i] = box;
  43.  
  44.                 addChild(box);
  45.  
  46.                 graphics.moveTo(100, y);
  47.                 graphics.lineTo(500, y);
  48.                 for (j = 0; j < 2; j ++) {
  49.                     textFormat.align = (j == 0)? TextFormatAlign.RIGHT: TextFormatAlign.LEFT;
  50.                     textField = new TextField();
  51.                     textField.defaultTextFormat = textFormat;
  52.                     textField.text = strings[i];
  53.                     textField.x = (j == 0)? 10: 510;
  54.                     textField.y = y - 8;
  55.                     textField.width = 80;
  56.                     addChild(textField);
  57.                 }
  58.             }
  59.         }
  60.  
  61.         private function createBox():Sprite {
  62.             var box:Sprite = new Sprite();
  63.             var graphics:Graphics = box.graphics;
  64.  
  65.             graphics.beginFill(0x0099cc);
  66.             graphics.drawRect(-5, -5, 10, 10);
  67.             graphics.endFill();
  68.  
  69.             return box;
  70.         }
  71.  
  72.         private function startTweensy():void{
  73.             var repeatTypes:Array = [
  74.                 TweensyTimeline.NONE,
  75.                 TweensyTimeline.REPLAY,
  76.                 TweensyTimeline.YOYO,
  77.                 TweensyTimeline.LOOP
  78.             ];
  79.  
  80.             var i:int, box:Sprite, timeline:TweensyTimeline;
  81.             for (i = 0; i < _boxes.length; i ++) {
  82.                 box = _boxes[i];
  83.                 timeline = Tweensy.to(box, { x: 500 }, 3, Quadratic.easeOut, 1);
  84.                 timeline.repeatType = repeatTypes[i];
  85.             }
  86.         }
  87.  
  88.  
  89.     }
  90.  
  91. }


About this entry