TweenerThreadでFF5のフレア
クリックしたところにフレア
// クリックしたところにフレア
package
{
import flash.display.Sprite;
import flash.events.*;
import org.libspark.thread.*;
[SWF(width=250, height=250, backgroundColor="0x305060", frameRate=60)]
public class Test extends Sprite
{
function Test()
{
if(!Thread.isReady) {
Thread.initialize(new EnterFrameThreadExecutor());
}
stage.mouseChildren = false;
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addChild(new Flare(120, 120));
}
private function onMouseDown(e:Event):void
{
addChild(new Flare(mouseX, mouseY));
}
}
}
import flash.display.*;
import flash.geom.*;
import org.libspark.thread.*;
import org.libspark.thread.utils.*;
import org.libspark.thread.threads.tweener.TweenerThread;
class Flare extends Sprite
{
function Flare(x:Number, y:Number)
{
this.x = x;
this.y = y;
var thread:FlareThread = new FlareThread(this);
thread.start();
}
public function vanish():void
{
parent.removeChild(this);
}
}
class FlareThread extends Thread
{
private var parent:Flare;
function FlareThread(parent:Flare)
{
this.parent = parent;
}
override protected function run():void
{
var pt:ParallelExecutor = new ParallelExecutor();
pt.addThread(new Circle1(parent, 3, 0));
pt.addThread(new Circle1(parent, 2, 1));
pt.addThread(new Circle1(parent, 0, 3));
pt.addThread(new Circle1(parent, 1, 4));
pt.addThread(new Circle1(parent, 4, 5));
pt.addThread(new Circle1(parent, 6, 5));
pt.addThread(new Circle1(parent, 5, 6));
pt.addThread(new Circle1(parent, 7, 7));
pt.start();
pt.join();
next(wait1);
}
private function wait1():void
{
wait(500);
next(run2)
}
private function run2():void
{
var pt:ParallelExecutor = new ParallelExecutor();
pt.addThread(new Circle2(parent, -2, -2, 0));
pt.addThread(new Circle2(parent, -1, 1, 0));
pt.addThread(new Circle2(parent, 2, 0, 0));
pt.addThread(new Circle2(parent, 0, -1, 1));
pt.addThread(new Circle2(parent, 1, 2, 1));
pt.addThread(new Circle2(parent, 1, -2, 2));
pt.addThread(new Circle2(parent, -1, -1, 3));
pt.addThread(new Circle2(parent, -2, 2, 3));
pt.addThread(new Circle2(parent, 1, 1, 3));
pt.addThread(new Circle2(parent, -2, 0, 4));
pt.addThread(new Circle2(parent, 0, 1, 4));
pt.addThread(new Circle2(parent, -1, 2, 4));
pt.addThread(new Circle2(parent, -2, -1, 5));
pt.addThread(new Circle2(parent, 0, 2, 5));
pt.addThread(new Circle2(parent, 2, -2, 5));
pt.addThread(new Circle2(parent, 0, 0, 6));
pt.start();
pt.join();
next(wait2);
}
private function wait2():void
{
wait(300);
next(run3)
}
private function run3():void
{
var pt:ParallelExecutor = new ParallelExecutor();
pt.addThread(new Circle3(parent, 3, 0));
pt.addThread(new Circle3(parent, 2, 1));
pt.addThread(new Circle3(parent, 1, 2));
pt.addThread(new Circle3(parent, 0, 3));
pt.addThread(new Circle3(parent, 5, 4));
pt.addThread(new Circle3(parent, 4, 5));
pt.addThread(new Circle3(parent, 6, 6));
pt.addThread(new Circle3(parent, 7, 9));
pt.start();
pt.join();
}
override protected function finalize():void
{
parent.vanish();
}
}
class Circle1 extends Thread
{
private var parent:Flare;
private var dir:int;
private var delay:Number;
private var sprite:Circle;
function Circle1(parent:Flare, dir:int, delay:Number)
{
this.parent = parent;
this.dir = dir;
this.delay = delay / 10;
}
override protected function run():void
{
sprite = new Circle();
parent.addChild(sprite);
var st:SerialExecutor = new SerialExecutor();
for(var i:int = 0; i < 3; i++)
{
if(i == 0) {
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 112), y:MathEx.getVectorY(dir*32, 112),
scaleX:1.25, scaleY:1.25, visible:true, delay:delay, time:-1
}));
}
else {
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 112), y:MathEx.getVectorY(dir*32, 112),
scaleX:1.25, scaleY:1.25, time:-1
}));
}
st.addThread(new TweenerThread(sprite, {
x:0, y:0, scaleX:0.25, scaleY:0.25, transition:"linear", time:0.5
}));
}
st.join();
st.start();
next(sprite.vanish);
}
}
class Circle2 extends Thread
{
private var parent:Flare;
private var x:int;
private var y:int;
private var delay:Number;
private var sprite:Circle;
function Circle2(parent:Flare, x:int, y:int, delay:Number)
{
this.parent = parent;
this.delay = delay / 10;
sprite = new Circle();
sprite.x = x * 16;
sprite.y = y * 16;
}
override protected function run():void
{
parent.addChild(sprite);
var st:SerialExecutor = new SerialExecutor();
st.addThread(new TweenerThread(sprite, {
scaleX:0.25, scaleY:0.25, visible:true, delay:delay, time:-1
}));
if(sprite.x == 0 && sprite.y == 0) {
st.addThread(new TweenerThread(sprite, {
scaleX:1.0, scaleY:1.0, skipUpdates:3, transition:"linear", time:0.3
}));
st.addThread(new TweenerThread(sprite, {
scaleX:5.0, scaleY:5.0, skipUpdates:3, transition:"linear", time:0.2
}));
}
else {
st.addThread(new TweenerThread(sprite, {
scaleX:1.0, scaleY:1.0, skipUpdates:3, transition:"linear", time:0.5
}));
}
st.join();
st.start();
next(sprite.vanish);
}
}
class Circle3 extends Thread
{
private var parent:Flare;
private var dir:int;
private var delay:Number;
private var sprite:Circle;
function Circle3(parent:Flare, dir:int, delay:Number)
{
this.parent = parent;
this.dir = dir;
this.delay = delay / 20;
}
override protected function run():void
{
sprite = new Circle();
parent.addChild(sprite);
var st:SerialExecutor = new SerialExecutor();
for(var i:int = 0; i < 3; i++)
{
if(i == 0) {
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 24), y:MathEx.getVectorY(dir*32, 24),
scaleX:0.25, scaleY:0.25,
visible:true, delay:delay, time:-1
}));
}
else {
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 24), y:MathEx.getVectorY(dir*32, 24),
scaleX:0.25, scaleY:0.25,
time:-1
}));
}
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 24), y:MathEx.getVectorY(dir*32, 24),
scaleX:0.8, scaleY:0.8, transition:"linear", time:0.02
}));
st.addThread(new TweenerThread(sprite, {
x:MathEx.getVectorX(dir*32, 96), y:MathEx.getVectorY(dir*32, 96),
scaleX:1.0, scaleY:1.0, transition:"linear", time:0.05
}));
}
st.join();
st.start();
next(sprite.vanish);
}
}
class Circle extends Sprite
{
function Circle()
{
var matrix:Matrix = new Matrix();
matrix.createGradientBox(16, 16, 0, -8, -8);
graphics.beginGradientFill(
"radial",
[0xFFFFFF, 0xFFC000, 0xF02000],
[100, 100, 100],
[0xB0, 0xD8, 0xF0],
matrix
);
graphics.drawCircle(0, 0, 8);
graphics.endFill();
visible = false;
}
public function vanish():void
{
parent.removeChild(this);
}
}
class MathEx
{
public static function getVectorX(dir:Number, speed:Number):Number {
return Math.cos(Math.PI/128*dir)*speed;
}
public static function getVectorY(dir:Number, speed:Number):Number {
return Math.sin(Math.PI/128*dir)*speed;
}
}