TweensyGroup - shortCuts
TweensyGroupクラスには、ショートカットメソッドが用意されている。
TweensyGroupのASDocによるとこんな感じ。
- alphaTo
- brightnessTo
- colorTo
- colorTransformTo
- contrastTo
- filterTo
- matrixTo
- rotateTo
- scaleTo
- slideTo
- soundTransformTo
今回は、alphaTo/scaleTo/rotateTo/slideToを使ってみた。
- 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();
}
}
} - 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.<int> = new Vector.<int>(8, true);
- var data:Vector.<number> = new Vector.<number>(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();
- }
- }
- }
About this entry
You’re currently reading “TweensyGroup - shortCuts,” an entry on jp.ferv.blog
- Published:
- Wed, May 20th, 2009 at 1:04 AM
- Author:
- dsk
- Category:
- Web
- Tags:
- ActionScript 3.0, Tweensy
No comments
Jump to comment form | comments rss | trackback uri