PhysicsParticle (com.robertpenner.physics.PhysicsParticle)

com.robertpenner.physics.PhysicsParticle
class PhysicsParticle

The PhysicsParticle class controls a MovieClip, turning it into a particle driven by physics forces. Designed to collaborate with the Force class (and subclasses).

Availability:

ActionScript 2.0; Flash Player 6

Property summary

Property Description
position:Vector

The position property of the PhysicsParticle.

velocity:Vector

The velocity property of the PhysicsParticle.

friction:Vector

The friction property of the PhysicsParticle.

xProp:String

The xProp property of the PhysicsParticle.

yProp:String

The yProp property of the PhysicsParticle.

Method summary

Method Description
addForce(id:String, force:Force) : Void

Adds a force to a PhysicsParticle instance.

removeForce(id:String) : Void

Removes a force from a PhysicsParticle instance.

getPosition() : Vector

Gets the position of a PhysicsParticle instance.

setPosition(x:Number, y:Number) : Void

Sets the position of a PhysicsParticle instance.

getVelocity() : Vector

Gets the velocity of a PhysicsParticle instance.

setVelocity(vx:Number, vy:Number) : Void

Sets the velocity of a PhysicsParticle instance.

getFriction() : Vector

Gets the friction of a PhysicsParticle instance.

setFriction(fx:Number, fy:Number) : Void

Sets the friction of a PhysicsParticle instance.

setXYProps(xp:String, yp:String) : Void

Sets both xProp and yProp of the PhysicsParticle.

PhysicsParticle(target:MovieClip, x:Number, y:Number, xProp:String, yProp:String)

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");

Parameters

target:MovieClip - The MovieClip that represents the particle visually.

x:Number - The initial x position of the particle.

y:Number - The initial y position of the particle.

xProp:String - The name of the property to link to the x component of the position; this defaults to "_x" if the parameter is omitted.

yProp:String - The name of the property to link to the y component of the position; this defaults to "_y" if the parameter is omitted.

Description

Creates an instance of the PhysicsParticle class.


addForce(id:String, force:Force) : Void

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");
var gravityForce:Force = new Force(0, .5);
p.addForce("gravity", gravityForce);

Parameters

id:String - A string that gives the force a unique identifier.

force:Force - An instance of the Force class that will be applied to the particle.

Returns

Nothing.

Description

Adds a force to a PhysicsParticle instance.


removeForce(id:String) : Void

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");
var gravityForce:Force = new Force(0, .5);
p.addForce("gravity", gravityForce);
p.removeForce("gravity");

Parameters

id:String - The string identifier of the force to remove.

Returns

Nothing.

Description

Removes a force from a PhysicsParticle instance.


getPosition() : Vector

Usage


trace (p.getPosition());

Parameters

Returns

Nothing.

Description

Gets the position of a PhysicsParticle instance.


setPosition(x:Number, y:Number) : Void

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");
p.setPosition(10, 10);

Parameters

x:Number - The x position of the PhysicsParticle.

y:Number - The y position of the PhysicsParticle.

Returns

Nothing.

Description

Sets the position of a PhysicsParticle instance.


getVelocity() : Vector

Usage


trace (p.getVelocity());

Parameters

Returns

Nothing.

Description

Gets the velocity of a PhysicsParticle instance.


setVelocity(vx:Number, vy:Number) : Void

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");
p.setVelocity(2, 0);

Parameters

vx:Number - The x velocity of the PhysicsParticle.

vy:Number - The y velocity of the PhysicsParticle.

Returns

Nothing.

Description

Sets the velocity of a PhysicsParticle instance.


getFriction() : Vector

Usage


trace (p.getFriction());

Parameters

Returns

Nothing.

Description

Gets the friction of a PhysicsParticle instance.


setFriction(fx:Number, fy:Number) : Void

Usage


var p:PhysicsParticle = new PhysicsParticle(this, 0, 0, "_x", "_yscale");
p.setFriction(.03, .001);

Parameters

fx:Number - The amount of friction to apply to the xProp of the PhysicsParticle.

fy:Number - The amount of friction to apply to the yProp of the PhysicsParticle.

Returns

Nothing.

Description

Sets the friction of a PhysicsParticle instance.


setXYProps(xp:String, yp:String) : Void

Usage


p.setXYProps("_xscale", "_yscale");

Parameters

Returns

Nothing.

Description

Sets both xProp and yProp of the PhysicsParticle.


position : Vector

Usage


trace (p.position);

Description

The position property of the PhysicsParticle.


velocity : Vector

Usage


trace (p.velocity);

Description

The velocity property of the PhysicsParticle.


friction : Vector

Usage


trace (p.position);

Description

The friction property of the PhysicsParticle.


xProp : String

Usage


trace (p.xProp);

Description

The xProp property of the PhysicsParticle.


yProp : String

Usage


trace (p.yProp);

Description

The yProp property of the PhysicsParticle.