many Balls
ループで親がballをトゥイーンさせるか、Ballクラスが自身でトゥイーンするか迷うんですが、大量系だと親がやった方が軽いのでしょうか。
♥0 |
Line 53 |
Modified 2011-06-28 17:26:03 |
MIT License
archived:2017-03-10 18:19:19
ActionScript3 source code
/**
* Copyright stylelab ( http://wonderfl.net/user/stylelab )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qq1Z
*/
package {
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.events.Event;
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.display.Shape;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.Expo;
//import org.libspark.betweenas3.events.TweenEvent;
public class FlashTest extends Sprite {
private var sw:int;
private var sh:int;
private var ballNum:int=2000;
private var ballSize:int=2;
private var balls:Array=[];
public function FlashTest() {
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(e:Event=null):void{
sw=stage.stageWidth;
sh=stage.stageHeight;
createBall();
stage.addEventListener(MouseEvent.CLICK,onClick);
}
private function createBall():void{
for(var i:int=0;i<ballNum;i++){
var ball:Ball=new Ball(ballSize,Math.random()*0xffffff);
addChild(ball);
ball.x=Math.random()*sw;
ball.y=Math.random()*sh;
balls.push(ball);
}
}
private function onClick(e:MouseEvent):void{
for(var i:int=0;i<ballNum;i++){
BetweenAS3.tween(balls[i],{x:balls[i].x+Math.random()*200-100,y:balls[i].y+Math.random()*200-100},null,2,Expo.easeOut).play();
//Tweener.addTween(balls[i],{x:balls[i].x+Math.random()*100-50,y:balls[i].y+Math.random()*100-50,time:3});
}
}
}
}
import flash.display.Sprite;
import flash.display.Shape;
class Ball extends Sprite{
public var col:uint;
public var w:int;
public function Ball(w:int,col:uint){
var sp:Shape=new Shape();
sp.graphics.beginFill(col);
sp.graphics.drawCircle(0,0,w);
sp.graphics.endFill();
addChild(sp)
}
}