Flint Particle System Forum - Explosion using MovieClips as particles Mon, 12 Dec 2011 00:28:27 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Explosion using MovieClips as particles http://flintparticles.org/forum/comments.php?DiscussionID=440&Focus=1499#Comment_1499 http://flintparticles.org/forum/comments.php?DiscussionID=440&Focus=1499#Comment_1499 Tue, 04 Jan 2011 03:48:41 +0000 ven
-Ven


package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.*;

import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.initializers.*;
import org.flintparticles.twoD.renderers.*;

import org.flintparticles.twoD.particles.Particle2DUtils;

public class FlintExpl extends MovieClip
{
var emitter:Emitter2D = new Emitter2D();

function FlintExpl()
{
// setup display
init();

// wait for click
stage.addEventListener( MouseEvent.CLICK, mouseClick );
}

// handle mouse click, start emitter when mouse is clicked
function mouseClick( e:MouseEvent )
{
emitter.start();
}

// create a grid of blocks (jewels) 8x8 and then setup for explosion in the middle of grid
function init()
{
// here we create an array of our movieclip objects to be use as particles, ideally this would
// already be filled before passing to the explosion handler.
var jewels:Array = new Array();

// setup for grid
const INIT_X = 100; // grid x,y corner point
const INIT_Y = 100;

var ix:int = INIT_X; // used in setting starting points for grid rows, cols
var iy:int = INIT_Y;

var height:int = 20; // dimensions of object
var width:int = 20;
const SPC = 3; // spacing between objects

for ( var i:int = 0; i < 8; i++ )
{
for ( var j:int = 0; j < 8; j++ )
{
var obj:Jewel = new Jewel;

obj.x = ix + ((SPC + width) * j );
obj.y = iy;
jewels.push( obj );
}
iy += SPC + height;
}

// create particles from our existing objects
var particles:Array = Particle2DUtils.createParticles2DFromDisplayObjects( jewels );

// add particles
emitter.addExistingParticles( particles, false );

// add renderer
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
renderer.addEmitter( emitter);
addChild( renderer );

// set up the explosion - good to play with explosion strenght, depth and epsilon
// the object's origin is in the center, so need to offsets in x/y to get to center of grid
// check Explosion constructor documentation
emitter.addAction(new Explosion(1,(INIT_X + (width + SPC) * 4) - ((width+SPC)/2), (INIT_Y + (height + SPC) * 4 ) - ((height+SPC)/2), 300, 10)); // set up explosion
emitter.addAction( new Move() ); // set to objects to move

// TODO: here we can limit how far out the explosions will go


// start emitter when mouse is clicked
// emitter.start();
}
}
}
]]>