Packagecom.whirled.contrib.display
Classpublic class PhysicalBase
InheritancePhysicalBase Inheritance flash.display.MovieClip

This class allows Movie Clips to move in accordance with simple physics including acceleration and drag. There are no collision dynamics in this class. However, this is useful for animating projectiles or particles.

Important! The convention for coordinates in Flash is that an increase in the y direction indicates movement in a downward direction. To apply an acceleration that forces objects downwards use a positive acceleration, not a negative acceleration.

This class is meant to be extended.

Author: jdnx429



Public Properties
 PropertyDefined by
  accelX : Number = 0
The x component of the object's acceleration in pixels/second/second.
PhysicalBase
  accelY : Number = 0
The y component of the object's acceleration in pixels/second/second.
PhysicalBase
  drag : Number = 0.0
The drag constant of the object.
PhysicalBase
  dragLimit : Number = 1000
The minimum speed at which drag occurs in pixels/second.
PhysicalBase
  physicalTimer : Timer
The timer that controls object updating.
PhysicalBase
  speedX : Number = 0
The x component of the object's speed in pixels/second.
PhysicalBase
  speedY : Number = 0
The y component of the object's speed in pixels/second.
PhysicalBase
Public Methods
 MethodDefined by
  
PhysicalBase(xpos:Number, ypos:Number)
Creates a PhysicalBase object at the location specfied.
PhysicalBase
  
addAccVector(acc:Number, angle:Number):void
Check this, watch speed and accel.
PhysicalBase
  
addSpeedVector(speed:Number, angle:Number):void
Adds the current speed vector with the supplied vector.
PhysicalBase
  
destroy():void
Destroys the object.
PhysicalBase
  
getAngle():Number
Returns the current direction of the object.
PhysicalBase
  
getSpeed():Number
Returns the current speed of the object in pixels per second.
PhysicalBase
  
halt():void
Sets all speed and acceleration to 0, stopping the object.
PhysicalBase
  
setAccComp(xacc:Number, yacc:Number):void
Sets the acceleration of the object using x and y components.
PhysicalBase
  
setAccVector(acc:Number, angle:Number):void
Sets the acceleration of the object using a vector.
PhysicalBase
  
setDrag(dragnum:Number, dragLimitnum:Number):void
Sets the drag and the drag limit of the object.
PhysicalBase
  
setLocation(xpos:Number, ypos:Number):void
Sets the location of the object.
PhysicalBase
  
setSpeedComp(xnum:Number, ynum:Number):void
Sets the speed of the object using the x and y components.
PhysicalBase
  
setSpeedVector(speed:Number, angle:Number):void
Sets the speed of the object using the speed of the object and an angle.
PhysicalBase
  
startMoving():void
Initializes the Timer that controls the object and starts moving the object in accordance with its properties.
PhysicalBase
Protected Methods
 MethodDefined by
  
applyDrag():void
PhysicalBase
Property detail
accelXproperty
public var accelX:Number = 0

The x component of the object's acceleration in pixels/second/second.

accelYproperty 
public var accelY:Number = 0

The y component of the object's acceleration in pixels/second/second. A positive number indicates a downward direction.

dragproperty 
public var drag:Number = 0.0

The drag constant of the object. The range is typically 0.0 to 5.0. The ultimate decceleration force is a combination of the drag constant and the speed of the object.

dragLimitproperty 
public var dragLimit:Number = 1000

The minimum speed at which drag occurs in pixels/second. While the object is below this speed no drag is applied. At speeds above the dragLimit, drag progressively increases with speed.

physicalTimerproperty 
public var physicalTimer:Timer

The timer that controls object updating. This is set to 33.333 milliseconds which translates to 30 frames per second. Changing the delay of the timer won't change the speed of the objects, only how often the objects are rendered.

speedXproperty 
public var speedX:Number = 0

The x component of the object's speed in pixels/second.

speedYproperty 
public var speedY:Number = 0

The y component of the object's speed in pixels/second. A positive number indicates a downward direction.

Constructor detail
PhysicalBase()constructor
public function PhysicalBase(xpos:Number, ypos:Number)

Creates a PhysicalBase object at the location specfied.

Parameters
xpos:Number — - the x-coordinate of the object.
 
ypos:Number — - the y-coordinate of the object.
Method detail
addAccVector()method
public function addAccVector(acc:Number, angle:Number):void

Check this, watch speed and accel.

Parameters
acc:Number
 
angle:Number
addSpeedVector()method 
public function addSpeedVector(speed:Number, angle:Number):void

Adds the current speed vector with the supplied vector.

Parameters
speed:Number — the speed of the speed vector to be added to the object.
 
angle:Number — the angle of the speed vector to be added to the object. This is set in degrees.
applyDrag()method 
protected function applyDrag():void
destroy()method 
public function destroy():void

Destroys the object. Removes the EventListener to the Timer that controls the object and removes it from the Stage or parent Movie Clip

getAngle()method 
public function getAngle():Number

Returns the current direction of the object.

Returns
Number — the angle in degrees that the object is moving in.
getSpeed()method 
public function getSpeed():Number

Returns the current speed of the object in pixels per second.

Returns
Number — the speed of the object.
halt()method 
public function halt():void

Sets all speed and acceleration to 0, stopping the object.

setAccComp()method 
public function setAccComp(xacc:Number, yacc:Number):void

Sets the acceleration of the object using x and y components.

Parameters
xacc:Number — the x component of the acceleration.
 
yacc:Number — the y component of the acceleration.
setAccVector()method 
public function setAccVector(acc:Number, angle:Number):void

Sets the acceleration of the object using a vector.

Parameters
acc:Number — the acceleration of the object.
 
angle:Number — the angle of the applied acceleration in degrees. Y-coordinates are positive in the downward direction. An angle of 90 degrees is therefore straight down.
setDrag()method 
public function setDrag(dragnum:Number, dragLimitnum:Number):void

Sets the drag and the drag limit of the object.

Parameters
dragnum:Number — the drag of the object.
 
dragLimitnum:Number — the dragLimit of the object.
setLocation()method 
public function setLocation(xpos:Number, ypos:Number):void

Sets the location of the object.

Parameters
xpos:Number — the x-coordinate of the object.
 
ypos:Number — the y-coordinate of the object.
setSpeedComp()method 
public function setSpeedComp(xnum:Number, ynum:Number):void

Sets the speed of the object using the x and y components.

Parameters
xnum:Number — the x component of the speed.
 
ynum:Number — the y component of the speed.
setSpeedVector()method 
public function setSpeedVector(speed:Number, angle:Number):void

Sets the speed of the object using the speed of the object and an angle.

Parameters
speed:Number — the speed of the object
 
angle:Number — the angle of the object - this is set in degrees. Remember that y is positive the downward direction. An angle of 90 degrees therefore is straight down.
startMoving()method 
public function startMoving():void

Initializes the Timer that controls the object and starts moving the object in accordance with its properties.