-
- CommentAuthordfdiaza
- CommentTimeNov 6th 2012
This is my second day using Flint and I have a doubt.
I have some particles moving inside a BoundingBox, but I need to have a Slider control, so I can change the particles velocity without change their directions.
I don't have idea how to achieve it. Can you help me please?
Regards,
Diego
Here is the current code with the particles inside a BoundingBox
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.RadialDot;
import org.flintparticles.common.initializers.*;
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.zones.*;
var emitter:Emitter2D = new Emitter2D();
emitter.counter = new Blast( 10 );
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
renderer.addEmitter( emitter );
addChild( renderer );
var moleculeGroup:InitializerGroup = new InitializerGroup();
moleculeGroup.addInitializer(new ImageClass(Asteroide) );
var bounds:Rectangle = new Asteroide().getBounds(this);
moleculeGroup.addInitializer(
new CollisionRadiusInit(
Math.max(bounds.width,
bounds.height)/2)
);
moleculeGroup.addInitializer(new Position( new RectangleZone( 150,150,300,300) ));
moleculeGroup.addInitializer(new Velocity( new PointZone( new Point( 100,100 ))));
emitter.addInitializer(moleculeGroup);
emitter.addAction( new Move() );
emitter.addAction(new Collide(1));
emitter.addAction(new BoundingBox(150,150,300,300))
emitter.start();
//TODO:
function changeSpeed()
{
how can I change the speed for all the particles from my emitter?
} -
- CommentAuthordfdiaza
- CommentTimeNov 6th 2012
Never mind. I don't know if this is the correct way to achieve this, but I found a solution.
for(var i=0;i<emitter.particles.length;i++)
{
var p:Particle2D = Particle2D( emitter.particles[i] );
var loc:Point = new Point(velocity,velocity) // A point zone with my desired velocity.
if( p.rotation == 0 )
{
p.velX = loc.x;
p.velY = loc.y;
}
else
{
var sin:Number = Math.sin( p.rotation );
var cos:Number = Math.cos( p.rotation );
p.velX = cos * loc.x - sin * loc.y;
p.velY = cos * loc.y + sin * loc.x;
}
}
1 to 2 of 2
