TweensyGroup - shortCuts

TweensyGroupクラスには、ショートカットメソッドが用意されている。

TweensyGroupのASDocによるとこんな感じ。

  • alphaTo
  • brightnessTo
  • colorTo
  • colorTransformTo
  • contrastTo
  • filterTo
  • matrixTo
  • rotateTo
  • scaleTo
  • slideTo
  • soundTransformTo
ここまでやるなら、contrastTo/hueRotationTo/saturationTo/volumeTo/panToとかもあってもいいけどまだないみたい。

今回は、alphaTo/scaleTo/rotateTo/slideToを使ってみた。

TestTweensy_11.swf

  • ActionScript
  • TestTweensy_11.as
  • Source
package  {
	import com.flashdynamix.motion.TweensyGroup;
	import fl.motion.easing.Bounce;
	import fl.motion.easing.Elastic;
	import fl.motion.easing.Linear;
	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;

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

		private var _arrow:Sprite;
		private var _textField:TextField;

		public function TestTweensy_11() {
			initArrow();
			initTextField();

			startTweensyGroup();
		}

		private function initArrow():void {
			_arrow = createArrow();
			_arrow.x = stage.stageWidth / 2;
			_arrow.y = stage.stageHeight / 2;
			addChild(_arrow);
		}

		private function createArrow():Sprite {
			var arrow:Sprite = new Sprite();
			var graphics:Graphics = arrow.graphics;
			var commands:Vector. = new Vector.(8, true);
			var data:Vector. = new Vector.(16, true);

			commands[0] = 1;
			commands[1] = commands[2] = commands[3] = commands[4] = commands[5] = commands[6] = commands[7] = 2;
			data[0] = 10; data[1] = 0;
			data[2] = 0; data[3] = -10;
			data[4] = 0; data[5] = -5;
			data[6] = -10; data[7] = -5;
			data[8] = -10; data[9] = 5;
			data[10] = 0; data[11] = 5;
			data[12] = 0; data[13] = 10;
			data[14] = 10; data[15] = 0;

			graphics.beginFill(0x0099cc);
			graphics.drawPath(commands, data);
			graphics.endFill();

			return arrow;
		}

		private function initTextField():void{
			_textField = createTextField();
			_textField.x = 10;
			_textField.y = 10;
			addChild(_textField);
		}

		private function createTextField():TextField {
			var textField:TextField = new TextField();
			var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);

			textField.defaultTextFormat = textFormat;
			textField.autoSize = TextFieldAutoSize.LEFT;

			return textField;
		}

		private function startTweensyGroup():void {
			var tweensyGroup:TweensyGroup = new TweensyGroup();
			var targetX:Number = Math.random() * stage.stageWidth;
			var targetY:Number = Math.random() * stage.stageHeight;
			var targetRotation:Number = Math.atan2(targetY - _arrow.y, targetX - _arrow.x) / Math.PI * 180;

			tweensyGroup.slideTo(_arrow, targetX, targetY, 3, Quadratic.easeInOut, 1);
			tweensyGroup.scaleTo(_arrow, 1 + Math.random() * 4, 2, Bounce.easeOut, 2);
			tweensyGroup.rotateTo(_arrow, targetRotation, 4, Elastic.easeOut);
			tweensyGroup.alphaTo(_arrow, 0.5 + Math.random() * 0.5, 1, Linear.easeNone, 3);

			tweensyGroup.onUpdate = onTweensyGroupUpdate;
			tweensyGroup.onComplete = onTweensyGroupComplete;
		}

		private function onTweensyGroupUpdate():void{
			var text:String = '';

			text += '_arrow.x = ' + _arrow.x + '\n';
			text += '_arrow.y = ' + _arrow.y + '\n';
			text += '_arrow.scaleX = ' + _arrow.scaleX + '\n';
			text += '_arrow.scaleY = ' + _arrow.scaleY + '\n';
			text += '_arrow.rotation = ' + _arrow.rotation + '\n';
			text += '_arrow.alpha = ' + _arrow.alpha;

			_textField.text = text;
		}

		private function onTweensyGroupComplete():void{
			startTweensyGroup();
		}


	}

}
  1. package  {
  2.     import com.flashdynamix.motion.TweensyGroup;
  3.     import fl.motion.easing.Bounce;
  4.     import fl.motion.easing.Elastic;
  5.     import fl.motion.easing.Linear;
  6.     import fl.motion.easing.Quadratic;
  7.     import flash.display.Graphics;
  8.     import flash.display.Sprite;
  9.     import flash.text.TextField;
  10.     import flash.text.TextFieldAutoSize;
  11.     import flash.text.TextFormat;
  12.  
  13.     [SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
  14.     public class TestTweensy_11 extends Sprite {
  15.  
  16.         private var _arrow:Sprite;
  17.         private var _textField:TextField;
  18.  
  19.         public function TestTweensy_11() {
  20.             initArrow();
  21.             initTextField();
  22.  
  23.             startTweensyGroup();
  24.         }
  25.  
  26.         private function initArrow():void {
  27.             _arrow = createArrow();
  28.             _arrow.x = stage.stageWidth / 2;
  29.             _arrow.y = stage.stageHeight / 2;
  30.             addChild(_arrow);
  31.         }
  32.  
  33.         private function createArrow():Sprite {
  34.             var arrow:Sprite = new Sprite();
  35.             var graphics:Graphics = arrow.graphics;
  36.             var commands:Vector.<int> = new Vector.<int>(8, true);
  37.             var data:Vector.<number> = new Vector.<number>(16, true);
  38.  
  39.             commands[0] = 1;
  40.             commands[1] = commands[2] = commands[3] = commands[4] = commands[5] = commands[6] = commands[7] = 2;
  41.             data[0] = 10; data[1] = 0;
  42.             data[2] = 0; data[3] = -10;
  43.             data[4] = 0; data[5] = -5;
  44.             data[6] = -10; data[7] = -5;
  45.             data[8] = -10; data[9] = 5;
  46.             data[10] = 0; data[11] = 5;
  47.             data[12] = 0; data[13] = 10;
  48.             data[14] = 10; data[15] = 0;
  49.  
  50.             graphics.beginFill(0x0099cc);
  51.             graphics.drawPath(commands, data);
  52.             graphics.endFill();
  53.  
  54.             return arrow;
  55.         }
  56.  
  57.         private function initTextField():void{
  58.             _textField = createTextField();
  59.             _textField.x = 10;
  60.             _textField.y = 10;
  61.             addChild(_textField);
  62.         }
  63.  
  64.         private function createTextField():TextField {
  65.             var textField:TextField = new TextField();
  66.             var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);
  67.  
  68.             textField.defaultTextFormat = textFormat;
  69.             textField.autoSize = TextFieldAutoSize.LEFT;
  70.  
  71.             return textField;
  72.         }
  73.  
  74.         private function startTweensyGroup():void {
  75.             var tweensyGroup:TweensyGroup = new TweensyGroup();
  76.             var targetX:Number = Math.random() * stage.stageWidth;
  77.             var targetY:Number = Math.random() * stage.stageHeight;
  78.             var targetRotation:Number = Math.atan2(targetY - _arrow.y, targetX - _arrow.x) / Math.PI * 180;
  79.  
  80.             tweensyGroup.slideTo(_arrow, targetX, targetY, 3, Quadratic.easeInOut, 1);
  81.             tweensyGroup.scaleTo(_arrow, 1 + Math.random() * 4, 2, Bounce.easeOut, 2);
  82.             tweensyGroup.rotateTo(_arrow, targetRotation, 4, Elastic.easeOut);
  83.             tweensyGroup.alphaTo(_arrow, 0.5 + Math.random() * 0.5, 1, Linear.easeNone, 3);
  84.  
  85.             tweensyGroup.onUpdate = onTweensyGroupUpdate;
  86.             tweensyGroup.onComplete = onTweensyGroupComplete;
  87.         }
  88.  
  89.         private function onTweensyGroupUpdate():void{
  90.             var text:String = '';
  91.  
  92.             text += '_arrow.x = ' + _arrow.x + '\n';
  93.             text += '_arrow.y = ' + _arrow.y + '\n';
  94.             text += '_arrow.scaleX = ' + _arrow.scaleX + '\n';
  95.             text += '_arrow.scaleY = ' + _arrow.scaleY + '\n';
  96.             text += '_arrow.rotation = ' + _arrow.rotation + '\n';
  97.             text += '_arrow.alpha = ' + _arrow.alpha;
  98.  
  99.             _textField.text = text;
  100.         }
  101.  
  102.         private function onTweensyGroupComplete():void{
  103.             startTweensyGroup();
  104.         }
  105.  
  106.  
  107.     }
  108.  
  109. }


About this entry