パーティクル
package {
import __AS3__.vec.Vector;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
[SWF(backgroundColor="#000000", frameRate="30", width="512", height="512")]
public class Explosion extends Sprite
{
private const GRAVITY:Number = 0.1; //重力
private var particles:Vector.<Particle>;
private var w:Number;
private var h:Number;
public function Explosion()
{
if(stage)
addEventListener(Event.ADDED_TO_STAGE, init);
else
init();
}
private function init(event:Event = null):void{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
removeEventListener(Event.ADDED_TO_STAGE, init);
w = stage.stageWidth;
h = stage.stageHeight;
particles = new Vector.<Particle>();
stage.addEventListener(MouseEvent.MOUSE_MOVE, mMove);
addEventListener(Event.ENTER_FRAME, loop);
}
private function mMove(event:MouseEvent):void{ //円を飛び散らせる
particles = particles.filter(func);
var pos:Point = new Point(mouseX, mouseY); //クリックした座標
var n:uint = Math.floor(Math.random() * 10);
var p:Particle;
for(var i:uint = 0; i < n; i++){
p = new Particle(pos.x, pos.y, Math.random()*10-5, Math.random()*10-5, Math.random()*20, Math.random()*0x00FFFF+ 0xFF0000);
particles.push(p);
addChild(p);
}
}
private function func(item:Particle, index:int, vec:Vector.<Particle>):Boolean{
if(item.x < 0 || item.x > w || item.y > h){
removeChild(item);
item.visible = false;
return false;
}
else
return true;
}
private function loop(event:Event):void{
for each(var p:Particle in particles){
p.x += p.vx;
p.y += p.vy;
p.vy += GRAVITY;
}
}
}
}
import flash.display.Shape;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
class Particle extends Shape{
public var vx:Number;
public var vy:Number;
public var size:Number;
public var color:uint;
public function Particle(x:Number=0, y:Number=0, vx:Number=0, vy:Number=0, size:Number=5, color:uint=0xFFFFFF):void{
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.size = size;
this.color = color;
this.blendMode = BlendMode.ADD;
this.filters = [new BlurFilter(10, 10, 1)];
graphics.beginFill(color);
graphics.drawCircle(0, 0, size);
graphics.endFill();
}
}