How to add more properties to a 2D particle?

10 views
Skip to first unread message

carlos.lunetta

unread,
Apr 11, 2010, 8:23:28 PM4/11/10
to Stardust Particle Engine
Hello all

I'm wondering what's the best way to add more properties to a 2D
particle; I need to add custom properties for animating it in a
specific way, but I'm not sure the best way to do it; Particle2D is
never directly instantiated... any hints?

Allen Chou

unread,
Apr 11, 2010, 11:41:05 PM4/11/10
to stardust-par...@googlegroups.com
The Particle.dictionary property is exactly for this purpose.

You can create a custom initializer and assign a custom property to a particle. Say you want to create a bubble motion, and you need an extra "phase" property. Your initializer's initialize() method may look like this.

override initialize(particle:Particle):void {
//creates a "phase" property with a random value of 0 to 2pi
particle.dictionary["phase"] = 2 * Math.PI * Math.random();
}

In you custom action, the property can be accessed by providing the key string "phase".

override update(particle:Particle, emitter:Emitter, time:Number):void {
var p2D:Particle2D = Particle2D(particle);
p2D.x = 100 * p2D.dictionary["phase"];
}

carlos.lunetta

unread,
Apr 19, 2010, 1:14:59 PM4/19/10
to Stardust Particle Engine
That's what I need!
Thanks a lot!


--
Subscription settings: http://groups.google.com/group/stardust-particle-engine/subscribe?hl=en
Reply all
Reply to author
Forward
0 new messages