Flint Particle System Forum - Change direction Sun, 13 Jun 2010 12:11:00 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.4 & Feed Publisher Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=282#Comment_282 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=282#Comment_282 Mon, 28 Jul 2008 16:24:11 +0100 simon
Currently I have particles moving from one position to another

eg: emitter.addAction( new TweenPosition( 10, 10, 300, 300 ) );

however when the particles reach x:300, y:300 I would like them to curve and start in a new direction say to x:400, y:500

so I am basically creating a path for the particles to follow that looks fairly natural.

How would I go about doing this? Thanks for you help.

Cheers
Simon ]]>
Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=283#Comment_283 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=283#Comment_283 Tue, 29 Jul 2008 07:56:47 +0100 Richard
Flint doesn't have an action for what you're trying to do, but fortunately it has been designed to make it easy to add additional functionality. You'll need to create a custom Action for the movement you want and to use this custom action with your emitter. Actions are quite simple - extend the action class and implement your own new update method. Take a look at the code in the TweenPosition class for ideas and see how you get on.

Alternatively, do your animations need to be precise? Can you get the effect you want using physics? Specifically, using a number of Jets - these are accelerations that only operate in particular regions (called zones in Flint). So you could start with a Jet to apply an acceleration in a zone around the start point of the particles which pushes them towards the first target point, then add another Jet near this new point that pushes them towards the second target, and so on. It won't be as precise as using a tween but may look more natural, depending on what you're after. ]]>
Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=284#Comment_284 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=284#Comment_284 Tue, 29 Jul 2008 09:35:06 +0100 simon
I'll try the jets first then creating a new actions class. Do you think it would be possible to use something like Tweener to control the particles? Then I could put in bezier ranges to create the curve effect in the correct places.

Cheers
Simon ]]>
Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=285#Comment_285 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=285#Comment_285 Tue, 29 Jul 2008 12:24:10 +0100 Richard Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=286#Comment_286 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=286#Comment_286 Wed, 30 Jul 2008 22:44:29 +0100 simon
----------------------------------------------------

package org.flintparticles.actions
{
import org.flintparticles.emitters.Emitter;
import org.flintparticles.particles.Particle;
import caurina.transitions.Tweener;
import caurina.transitions.properties.CurveModifiers;


/**
* The TweenPosition action adjusts the particle's position between two
* locations as it ages. This action
* should be used in conjunction with the Age action.
*/

public class TweenTo extends Action
{
private var _diffX:Number;
private var _endX:Number;
private var _diffY:Number;
private var _endY:Number;
private var _speed:Number;
private var _curvesArray:Array;

/**
* The constructor creates a TweenPosition action for use by
* an emitter. To add a TweenPosition to all particles created by an emitter, use the
* emitter's addAction method.
*
* @see org.flintparticles.emitters.Emitter#addAction()
*
* @param startX The x value for the particle at the
* start of its life.
* @param startY The y value for the particle at the
* start of its life.
* @param endX The x value of the particle at the end of its
* life.
* @param endY The y value of the particle at the end of its
* life.
*/
public function TweenTo( startX:Number, startY:Number, endX:Number, endY:Number, speed:Number, curvesArray:Array )
{
_diffX = startX - endX;
_endX = endX;
_diffY = startY - endY;
_endY = endY;
_speed = speed;
_curvesArray = curvesArray;

CurveModifiers.init();


}

/**
* The x position for the particle at the start of its life.
*/
public function get startX():Number
{
return _endX + _diffX;
}
public function set startX( value:Number ):void
{
_diffX = value - _endX;
}

/**
* The X value for the particle at the end of its life.
*/
public function get endX():Number
{
return _endX;
}
public function set endX( value:Number ):void
{
_diffX = _endX + _diffX - value;
_endX = value;
}

/**
* The y position for the particle at the start of its life.
*/
public function get startY():Number
{
return _endY + _diffY;
}
public function set startY( value:Number ):void
{
_diffY = value - _endY;
}

/**
* The y value for the particle at the end of its life.
*/
public function get endY():Number
{
return _endY;
}
public function set endY( value:Number ):void
{
_diffY = _endY + _diffY - value;
_endY = value;
}

/**
* @inheritDoc
*/
override public function update( emitter:Emitter, particle:Particle, time:Number ):void
{

if (Tweener.getTweenCount(particle) == 0){
Tweener.addTween(particle, { time:_speed, x:_endX, y:_endY, _bezier:_curvesArray,transition:"linear" } );
}

}
}
} ]]>
Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=288#Comment_288 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=288#Comment_288 Thu, 31 Jul 2008 07:23:12 +0100 Richard Change direction http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=289#Comment_289 http://flintparticles.org/forum/comments.php?DiscussionID=59&Focus=289#Comment_289 Thu, 31 Jul 2008 13:57:44 +0100 chien
I did something similar to what you are trying to do by creating a simple action which provides a way for an emitter to follow any object on the stage even those attached to a motion guide.

chien ]]>