Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing usage of particleClass in FlxEmitter #95

Merged
merged 6 commits into from
Oct 28, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions org/flixel/FlxEmitter.as
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ package org.flixel
* How much each particle should bounce. 1 = full bounce, 0 = no bounce.
*/
public var bounce:Number;
/**
* Set your own particle class type here.
* Default is <code>FlxParticle</code>.
*/
public var particleClass:Class;
/**
* Internal helper for deciding how many particles to launch.
*/
Expand All @@ -102,6 +97,11 @@ package org.flixel
* Internal point object, handy for reusing for memory mgmt purposes.
*/
protected var _point:FlxPoint;
/**
* Internal variable for tracking the class to create when generating particles.
*/
protected var _particleClass:Class;


/**
* Creates a new <code>FlxEmitter</code> object at a specific position.
Expand All @@ -123,7 +123,7 @@ package org.flixel
minRotation = -360;
maxRotation = 360;
gravity = 0;
particleClass = null;
_particleClass = FlxParticle;
particleDrag = new FlxPoint();
frequency = 0.1;
lifespan = 3;
Expand All @@ -143,15 +143,15 @@ package org.flixel
minParticleSpeed = null;
maxParticleSpeed = null;
particleDrag = null;
particleClass = null;
_particleClass = null;
_point = null;
super.destroy();
}

/**
* This function generates a new array of particle sprites to attach to the emitter.
*
* @param Graphics If you opted to not pre-configure an array of FlxSprite objects, you can simply pass in a particle image or sprite sheet.
* @param Graphics If you opted to not pre-configure an array of FlxParticle objects, you can simply pass in a particle image or sprite sheet.
* @param Quantity The number of particles to generate when using the "create from image" option.
* @param BakedRotations How many frames of baked rotation to use (boosts performance). Set to zero to not use baked rotations.
* @param Multiple Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
Expand All @@ -177,10 +177,8 @@ package org.flixel
var i:uint = 0;
while(i < Quantity)
{
if(particleClass == null)
particle = new FlxParticle();
else
particle = new particleClass();
particle = new particleClass() as FlxParticle;

if(Multiple)
{
randomFrame = FlxG.random()*totalFrames;
Expand Down Expand Up @@ -290,7 +288,7 @@ package org.flixel
*/
public function emitParticle():void
{
var particle:FlxParticle = recycle(FlxParticle) as FlxParticle;
var particle:FlxParticle = recycle(particleClass) as FlxParticle;
particle.lifespan = lifespan;
particle.elasticity = bounce;
particle.reset(x - (particle.width>>1) + FlxG.random()*width, y - (particle.height>>1) + FlxG.random()*height);
Expand Down Expand Up @@ -318,6 +316,28 @@ package org.flixel
particle.onEmit();
}

/**
* Set your own particle class type here. The custom class must extend <code>FlxParticle</code>.
* Default is <code>FlxParticle</code>.
*/
public function get particleClass():Class
{
return _particleClass;
}

public function set particleClass(value:Class):void
{
var testParticle:Object = new value();
if (testParticle is FlxParticle)
{
_particleClass = value;
}
else
{
FlxG.log("ERROR: " + FlxU.getClassName(testParticle, true) + " must extend FlxParticle in order to be used in a FlxEmitter.");
}
}

/**
* A more compact way of setting the width and height of the emitter.
*
Expand Down