Packageorg.flintparticles.twoD.actions
Classpublic class ApproachNeighbours
InheritanceApproachNeighbours Inheritance ActionBase Inheritance Object

The ApproachNeighbours action applies an acceleration to the particle to draw it towards other nearby particles. The size of the acceleration is constant, only the direction varies. This differentiates this action from the MutualGravity action, where the acceleration is proportional to the distance between the particles.

ApproachNeighbours is most commonly used when creating flocking behaviours. Flocking is usually a combination of ApproachNeighbours to draw particles together, MinimumDistance to stop them getting too close and MatchVelocity to make them match speed and direction of motion.

This action has a priority of 10, so that it executes before other actions.

See also

org.flintparticles.twoD.actions.MinimumDistance
org.flintparticles.twoD.actions.MatchVelocity


Public Properties
 PropertyDefined By
  acceleration : Number
The acceleration applied to approach the other particles.
ApproachNeighbours
  maxDistance : Number
The maximum distance, in pixels, over which this action operates.
ApproachNeighbours
 Inheritedpriority : int
Returns a default priority of 0 for this action.
ActionBase
Protected Properties
 PropertyDefined By
 Inherited_priority : int = 0
ActionBase
Public Methods
 MethodDefined By
  
ApproachNeighbours(maxDistance:Number = 0, acceleration:Number = 0)
The constructor creates an ApproachNeighbours action for use by an emitter.
ApproachNeighbours
  
addedToEmitter(emitter:Emitter):void
[override] Instructs the emitter to produce a sorted particle array for optimizing the calculations in the update method of this action.
ApproachNeighbours
 Inherited
This method does nothing.
ActionBase
  
update(emitter:Emitter, particle:Particle, time:Number):void
[override] Checks all particles near the current particle and applies the acceleration to move the particle towards their average position.
ApproachNeighbours
Property Detail
accelerationproperty
acceleration:Number

The acceleration applied to approach the other particles.


Implementation
    public function get acceleration():Number
    public function set acceleration(value:Number):void
maxDistanceproperty 
maxDistance:Number

The maximum distance, in pixels, over which this action operates. Particles further apart than this distance ignore each other.


Implementation
    public function get maxDistance():Number
    public function set maxDistance(value:Number):void
Constructor Detail
ApproachNeighbours()Constructor
public function ApproachNeighbours(maxDistance:Number = 0, acceleration:Number = 0)

The constructor creates an ApproachNeighbours action for use by an emitter. To add an ApproachNeighbours to all particles created by an emitter, use the emitter's addAction method.

Parameters
maxDistance:Number (default = 0) — The maximum distance, in pixels, over which this action operates. Particles further apart than this distance ignore each other.
 
acceleration:Number (default = 0) — The size of the acceleration applied to approach the other particles.

See also

Method Detail
addedToEmitter()method
override public function addedToEmitter(emitter:Emitter):void

Instructs the emitter to produce a sorted particle array for optimizing the calculations in the update method of this action.

Parameters

emitter:Emitter — The emitter this action has been added to.

See also

update()method 
override public function update(emitter:Emitter, particle:Particle, time:Number):void

Checks all particles near the current particle and applies the acceleration to move the particle towards their average position.

This method is called by the emitter and need not be called by the user.

Parameters

emitter:Emitter — The Emitter that created the particle.
 
particle:Particle — The particle to be updated.
 
time:Number — The duration of the frame - used for time based updates.

See also