Packagenet.flashpunk
Classpublic class FP
InheritanceFP Inheritance Object

Static catch-all class used to access global properties and functions.



Public Properties
 PropertyDefined By
  assignedFrameRate : Number
[static] The framerate assigned to the stage.
FP
  bounds : Rectangle
[static] A rectangle representing the size of the screen.
FP
  buffer : BitmapData
[static] The current screen buffer, drawn to in the render loop.
FP
  camera : Point
[static] Point used to determine drawing offset in the render loop.
FP
  console : Console
[static] [read-only] The global Console object.
FP
  elapsed : Number
[static] Time elapsed since the last frame (in seconds).
FP
  fixed : Boolean
[static] If the game is running at a fixed framerate.
FP
  focused : Boolean = true
[static] If the game currently has input focus or not.
FP
  frameRate : Number
[static] The framerate assigned to the stage.
FP
  halfHeight : Number
[static] Half height of the game.
FP
  halfWidth : Number
[static] Half width of the game.
FP
  height : uint
[static] Height of the game.
FP
  pan : Number
[static] Global panning factor for all sounds, a value from -1 to 1.
FP
  random : Number
[static] [read-only] A pseudo-random Number produced using FP's random seed, where 0 <= Number < 1.
FP
  randomSeed : uint
[static] The random seed used by FP's random functions.
FP
  rate : Number = 1
[static] Timescale applied to FP.elapsed.
FP
  screen : Screen
[static] The Screen object, use to transform or offset the Screen.
FP
  timeInFrames : Boolean
[static] If times should be given in frames (as opposed to seconds).
FP
  tweener : Tweener
[static] Global Tweener for tweening values across multiple worlds.
FP
  volume : Number
[static] Global volume factor for all sounds, a value from 0 to 1.
FP
  width : uint
[static] Width of the game.
FP
  world : World
[static] The currently active World object.
FP
Public Methods
 MethodDefined By
  
alarm(delay:Number, callback:Function, type:uint = 2, tweener:Tweener = null):Alarm
[static] Schedules a callback for the future.
FP
  
anchorTo(object:Object, anchor:Object, distance:Number = 0):void
[static] Anchors the object to a position.
FP
  
angle(x1:Number, y1:Number, x2:Number, y2:Number):Number
[static] Finds the angle (in degrees) from point 1 to point 2.
FP
  
angleDiff(a:Number, b:Number):Number
[static] Gets the difference of two angles, wrapped around to the range -180 to 180.
FP
  
angleXY(object:Object, angle:Number, length:Number = 1, x:Number = 0, y:Number = 0):void
[static] Sets the x/y values of the provided object to a vector of the specified angle and length.
FP
  
approach(value:Number, target:Number, amount:Number):Number
[static] Approaches the value towards the target, by the specified amount, without overshooting the target.
FP
  
choose(... objs):*
[static] Randomly chooses and returns one of the provided values.
FP
  
clamp(value:Number, min:Number, max:Number):Number
[static] Clamps the value within the minimum and maximum values.
FP
  
clampInRect(object:Object, x:Number, y:Number, width:Number, height:Number, padding:Number = 0):void
[static] Clamps the object inside the rectangle.
FP
  
[static] Clears the cache of BitmapData objects used by the getBitmap method.
FP
  
colorLerp(fromColor:uint, toColor:uint, t:Number = 1):uint
[static] Linear interpolation between two colors.
FP
  
distance(x1:Number, y1:Number, x2:Number = 0, y2:Number = 0):Number
[static] Find the distance between two points.
FP
  
distanceRectPoint(px:Number, py:Number, rx:Number, ry:Number, rw:Number, rh:Number):Number
[static] Find the distance between a point and a rectangle.
FP
  
distanceRects(x1:Number, y1:Number, w1:Number, h1:Number, x2:Number, y2:Number, w2:Number, h2:Number):Number
[static] Find the distance between two rectangles.
FP
  
frames(from:int, to:int, skip:int = 0):Array
[static] Gets an array of frame indices.
FP
  
getBitmap(source:Class):BitmapData
[static] Fetches a stored BitmapData object represented by the source.
FP
  
getBlue(color:uint):uint
[static] Finds the blue factor of a color.
FP
  
getColorHSV(h:Number, s:Number, v:Number):uint
[static] Creates a color value with the chosen HSV values.
FP
  
getColorHue(color:uint):Number
[static]
FP
  
getColorRGB(R:uint = 0, G:uint = 0, B:uint = 0):uint
[static] Creates a color value by combining the chosen RGB values.
FP
  
getColorSaturation(color:uint):Number
[static]
FP
  
getColorValue(color:uint):Number
[static]
FP
  
getGreen(color:uint):uint
[static] Finds the green factor of a color.
FP
  
getRed(color:uint):uint
[static] Finds the red factor of a color.
FP
  
getXML(file:Class):XML
[static] Loads the file as an XML object.
FP
  
lerp(a:Number, b:Number, t:Number = 1):Number
[static] Linear interpolation between two values.
FP
  
log(... data):void
[static] Logs data to the console.
FP
  
next(current:*, options:Array, loop:Boolean = true):*
[static] Returns the next item after current in the list of options.
FP
  
prev(current:*, options:Array, loop:Boolean = true):*
[static] Returns the item previous to the current in the list of options.
FP
  
rand(amount:uint):uint
[static] Returns a pseudo-random uint.
FP
  
[static] Randomizes the random seed using Flash's Math.random() function.
FP
  
remove(array:*, toRemove:*):Boolean
[static] Remove an element from an array
FP
  
[static] Resets the camera position.
FP
  
resize(width:int, height:int):void
[static] Resize the screen.
FP
  
rotateAround(object:Object, anchor:Object, angle:Number = 0, relative:Boolean = true):void
[static] Rotates the object around the anchor by the specified amount.
FP
  
scale(value:Number, min:Number, max:Number, min2:Number, max2:Number):Number
[static] Transfers a value from one scale to another scale.
FP
  
scaleClamp(value:Number, min:Number, max:Number, min2:Number, max2:Number):Number
[static] Transfers a value from one scale to another scale, but clamps the return value within the second scale.
FP
  
setCamera(x:Number = 0, y:Number = 0):void
[static] Sets the camera position.
FP
  
shuffle(a:Object):void
[static] Shuffles the elements in the array.
FP
  
sign(value:Number):int
[static] Finds the sign of the provided value.
FP
  
sort(object:Object, ascending:Boolean = true):void
[static] Sorts the elements in the array.
FP
  
sortBy(object:Object, property:String, ascending:Boolean = true):void
[static] Sorts the elements in the array by a property of the element.
FP
  
stepTowards(object:Object, x:Number, y:Number, distance:Number = 1):void
[static] Steps the object towards a point.
FP
  
swap(current:*, a:*, b:*):*
[static] Swaps the current item between a and b.
FP
  
timeFlag():uint
[static] Sets a time flag.
FP
  
tween(object:Object, values:Object, duration:Number, options:Object = null):MultiVarTween
[static] Tweens numeric public properties of an Object.
FP
  
watch(... properties):void
[static] Adds properties to watch in the console's debug panel.
FP
Public Constants
 ConstantDefined By
  VERSION : String = 1.7.2
[static] The FlashPunk major version.
FP
Property Detail
assignedFrameRateproperty
public static var assignedFrameRate:Number

The framerate assigned to the stage.

boundsproperty 
public static var bounds:Rectangle

A rectangle representing the size of the screen.

bufferproperty 
public static var buffer:BitmapData

The current screen buffer, drawn to in the render loop.

cameraproperty 
public static var camera:Point

Point used to determine drawing offset in the render loop.

consoleproperty 
console:Console  [read-only]

The global Console object.


Implementation
    public static function get console():Console
elapsedproperty 
public static var elapsed:Number

Time elapsed since the last frame (in seconds).

fixedproperty 
public static var fixed:Boolean

If the game is running at a fixed framerate.

focusedproperty 
public static var focused:Boolean = true

If the game currently has input focus or not. Note: may not be correct initially.

frameRateproperty 
public static var frameRate:Number

The framerate assigned to the stage.

halfHeightproperty 
public static var halfHeight:Number

Half height of the game.

halfWidthproperty 
public static var halfWidth:Number

Half width of the game.

heightproperty 
public static var height:uint

Height of the game.

panproperty 
pan:Number

Global panning factor for all sounds, a value from -1 to 1.


Implementation
    public static function get pan():Number
    public static function set pan(value:Number):void
randomproperty 
random:Number  [read-only]

A pseudo-random Number produced using FP's random seed, where 0 <= Number < 1.


Implementation
    public static function get random():Number
randomSeedproperty 
randomSeed:uint

The random seed used by FP's random functions.


Implementation
    public static function get randomSeed():uint
    public static function set randomSeed(value:uint):void
rateproperty 
public static var rate:Number = 1

Timescale applied to FP.elapsed.

screenproperty 
public static var screen:Screen

The Screen object, use to transform or offset the Screen.

timeInFramesproperty 
public static var timeInFrames:Boolean

If times should be given in frames (as opposed to seconds). Default is true in fixed timestep mode and false in variable timestep mode.

tweenerproperty 
public static var tweener:Tweener

Global Tweener for tweening values across multiple worlds.

volumeproperty 
volume:Number

Global volume factor for all sounds, a value from 0 to 1.


Implementation
    public static function get volume():Number
    public static function set volume(value:Number):void
widthproperty 
public static var width:uint

Width of the game.

worldproperty 
world:World

The currently active World object. When you set this, the World is flagged to switch, but won't actually do so until the end of the current frame.


Implementation
    public static function get world():World
    public static function set world(value:World):void
Method Detail
alarm()method
public static function alarm(delay:Number, callback:Function, type:uint = 2, tweener:Tweener = null):Alarm

Schedules a callback for the future. Shorthand for creating an Alarm tween, starting it and adding it to a Tweener.

Parameters

delay:Number — The duration to wait before calling the callback.
 
callback:Function — The function to be called.
 
type:uint (default = 2) — The tween type (PERSIST, LOOPING or ONESHOT). Defaults to ONESHOT.
 
tweener:Tweener (default = null) — The Tweener object to add this Alarm to. Defaults to FP.tweener.

Returns
Alarm — The added Alarm object. Example: FP.alarm(5.0, callbackFunction, Tween.LOOPING); // Calls callbackFunction every 5 seconds
anchorTo()method 
public static function anchorTo(object:Object, anchor:Object, distance:Number = 0):void

Anchors the object to a position.

Parameters

object:Object — The object to anchor.
 
anchor:Object — The anchor object.
 
distance:Number (default = 0) — The max distance object can be anchored to the anchor.

angle()method 
public static function angle(x1:Number, y1:Number, x2:Number, y2:Number):Number

Finds the angle (in degrees) from point 1 to point 2.

Parameters

x1:Number — The first x-position.
 
y1:Number — The first y-position.
 
x2:Number — The second x-position.
 
y2:Number — The second y-position.

Returns
Number — The angle from (x1, y1) to (x2, y2).
angleDiff()method 
public static function angleDiff(a:Number, b:Number):Number

Gets the difference of two angles, wrapped around to the range -180 to 180.

Parameters

a:Number — First angle in degrees.
 
b:Number — Second angle in degrees.

Returns
Number — Difference in angles, wrapped around to the range -180 to 180.
angleXY()method 
public static function angleXY(object:Object, angle:Number, length:Number = 1, x:Number = 0, y:Number = 0):void

Sets the x/y values of the provided object to a vector of the specified angle and length.

Parameters

object:Object — The object whose x/y properties should be set.
 
angle:Number — The angle of the vector, in degrees.
 
length:Number (default = 1) — The distance to the vector from (0, 0).
 
x:Number (default = 0) — X offset.
 
y:Number (default = 0) — Y offset.

approach()method 
public static function approach(value:Number, target:Number, amount:Number):Number

Approaches the value towards the target, by the specified amount, without overshooting the target.

Parameters

value:Number — The starting value.
 
target:Number — The target that you want value to approach.
 
amount:Number — How much you want the value to approach target by.

Returns
Number — The new value.
choose()method 
public static function choose(... objs):*

Randomly chooses and returns one of the provided values.

Parameters

... objs — The Objects you want to randomly choose from. Can be ints, Numbers, Points, etc.

Returns
* — A randomly chosen one of the provided parameters.
clamp()method 
public static function clamp(value:Number, min:Number, max:Number):Number

Clamps the value within the minimum and maximum values.

Parameters

value:Number — The Number to evaluate.
 
min:Number — The minimum range.
 
max:Number — The maximum range.

Returns
Number — The clamped value.
clampInRect()method 
public static function clampInRect(object:Object, x:Number, y:Number, width:Number, height:Number, padding:Number = 0):void

Clamps the object inside the rectangle.

Parameters

object:Object — The object to clamp (must have an x and y property).
 
x:Number — Rectangle's x.
 
y:Number — Rectangle's y.
 
width:Number — Rectangle's width.
 
height:Number — Rectangle's height.
 
padding:Number (default = 0)

clearBitmapCache()method 
public static function clearBitmapCache():void

Clears the cache of BitmapData objects used by the getBitmap method.

colorLerp()method 
public static function colorLerp(fromColor:uint, toColor:uint, t:Number = 1):uint

Linear interpolation between two colors.

Parameters

fromColor:uint — First color.
 
toColor:uint — Second color.
 
t:Number (default = 1) — Interpolation value. Clamped to the range [0, 1]. return RGB component-interpolated color value.

Returns
uint
distance()method 
public static function distance(x1:Number, y1:Number, x2:Number = 0, y2:Number = 0):Number

Find the distance between two points.

Parameters

x1:Number — The first x-position.
 
y1:Number — The first y-position.
 
x2:Number (default = 0) — The second x-position.
 
y2:Number (default = 0) — The second y-position.

Returns
Number — The distance.
distanceRectPoint()method 
public static function distanceRectPoint(px:Number, py:Number, rx:Number, ry:Number, rw:Number, rh:Number):Number

Find the distance between a point and a rectangle. Returns 0 if the point is within the rectangle.

Parameters

px:Number — The x-position of the point.
 
py:Number — The y-position of the point.
 
rx:Number — The x-position of the rect.
 
ry:Number — The y-position of the rect.
 
rw:Number — The width of the rect.
 
rh:Number — The height of the rect.

Returns
Number — The distance.
distanceRects()method 
public static function distanceRects(x1:Number, y1:Number, w1:Number, h1:Number, x2:Number, y2:Number, w2:Number, h2:Number):Number

Find the distance between two rectangles. Will return 0 if the rectangles overlap.

Parameters

x1:Number — The x-position of the first rect.
 
y1:Number — The y-position of the first rect.
 
w1:Number — The width of the first rect.
 
h1:Number — The height of the first rect.
 
x2:Number — The x-position of the second rect.
 
y2:Number — The y-position of the second rect.
 
w2:Number — The width of the second rect.
 
h2:Number — The height of the second rect.

Returns
Number — The distance.
frames()method 
public static function frames(from:int, to:int, skip:int = 0):Array

Gets an array of frame indices.

Parameters

from:int — Starting frame.
 
to:int — Ending frame.
 
skip:int (default = 0) — Skip amount every frame (eg. use 1 for every 2nd frame).

Returns
Array
getBitmap()method 
public static function getBitmap(source:Class):BitmapData

Fetches a stored BitmapData object represented by the source.

Parameters

source:Class — Embedded Bitmap class.

Returns
BitmapData — The stored BitmapData object.
getBlue()method 
public static function getBlue(color:uint):uint

Finds the blue factor of a color.

Parameters

color:uint — The color to evaluate.

Returns
uint — A uint from 0 to 255.
getColorHSV()method 
public static function getColorHSV(h:Number, s:Number, v:Number):uint

Creates a color value with the chosen HSV values.

Parameters

h:Number — The hue of the color (from 0 to 1).
 
s:Number — The saturation of the color (from 0 to 1).
 
v:Number — The value of the color (from 0 to 1).

Returns
uint — The color uint.
getColorHue()method 
public static function getColorHue(color:uint):Number

Parameters

color:uint

Returns
Number
getColorRGB()method 
public static function getColorRGB(R:uint = 0, G:uint = 0, B:uint = 0):uint

Creates a color value by combining the chosen RGB values.

Parameters

R:uint (default = 0) — The red value of the color, from 0 to 255.
 
G:uint (default = 0) — The green value of the color, from 0 to 255.
 
B:uint (default = 0) — The blue value of the color, from 0 to 255.

Returns
uint — The color uint.
getColorSaturation()method 
public static function getColorSaturation(color:uint):Number

Parameters

color:uint

Returns
Number
getColorValue()method 
public static function getColorValue(color:uint):Number

Parameters

color:uint

Returns
Number
getGreen()method 
public static function getGreen(color:uint):uint

Finds the green factor of a color.

Parameters

color:uint — The color to evaluate.

Returns
uint — A uint from 0 to 255.
getRed()method 
public static function getRed(color:uint):uint

Finds the red factor of a color.

Parameters

color:uint — The color to evaluate.

Returns
uint — A uint from 0 to 255.
getXML()method 
public static function getXML(file:Class):XML

Loads the file as an XML object.

Parameters

file:Class — The embedded file to load.

Returns
XML — An XML object representing the file.
lerp()method 
public static function lerp(a:Number, b:Number, t:Number = 1):Number

Linear interpolation between two values.

Parameters

a:Number — First value.
 
b:Number — Second value.
 
t:Number (default = 1) — Interpolation factor.

Returns
Number — When t=0, returns a. When t=1, returns b. When t=0.5, will return halfway between a and b. Etc.
log()method 
public static function log(... data):void

Logs data to the console.

Parameters

... data — The data parameters to log, can be variables, objects, etc. Parameters will be separated by a space (" ").

next()method 
public static function next(current:*, options:Array, loop:Boolean = true):*

Returns the next item after current in the list of options.

Parameters

current:* — The currently selected item (must be one of the options).
 
options:Array — An array of all the items to cycle through.
 
loop:Boolean (default = true) — If true, will jump to the first item after the last item is reached.

Returns
* — The next item in the list.
prev()method 
public static function prev(current:*, options:Array, loop:Boolean = true):*

Returns the item previous to the current in the list of options.

Parameters

current:* — The currently selected item (must be one of the options).
 
options:Array — An array of all the items to cycle through.
 
loop:Boolean (default = true) — If true, will jump to the last item after the first is reached.

Returns
* — The previous item in the list.
rand()method 
public static function rand(amount:uint):uint

Returns a pseudo-random uint.

Parameters

amount:uint — The returned uint will always be 0 <= uint < amount.

Returns
uint — The uint.
randomizeSeed()method 
public static function randomizeSeed():void

Randomizes the random seed using Flash's Math.random() function.

remove()method 
public static function remove(array:*, toRemove:*):Boolean

Remove an element from an array

Parameters

array:*
 
toRemove:*

Returns
Boolean — True if element existed and has been removed, false if element was not in array.
resetCamera()method 
public static function resetCamera():void

Resets the camera position.

resize()method 
public static function resize(width:int, height:int):void

Resize the screen.

Parameters

width:int — New width.
 
height:int — New height.

rotateAround()method 
public static function rotateAround(object:Object, anchor:Object, angle:Number = 0, relative:Boolean = true):void

Rotates the object around the anchor by the specified amount.

Parameters

object:Object — Object to rotate around the anchor.
 
anchor:Object — Anchor to rotate around.
 
angle:Number (default = 0) — The amount of degrees to rotate by.
 
relative:Boolean (default = true)

scale()method 
public static function scale(value:Number, min:Number, max:Number, min2:Number, max2:Number):Number

Transfers a value from one scale to another scale. For example, scale(.5, 0, 1, 10, 20) == 15, and scale(3, 0, 5, 100, 0) == 40.

Parameters

value:Number — The value on the first scale.
 
min:Number — The minimum range of the first scale.
 
max:Number — The maximum range of the first scale.
 
min2:Number — The minimum range of the second scale.
 
max2:Number — The maximum range of the second scale.

Returns
Number — The scaled value.
scaleClamp()method 
public static function scaleClamp(value:Number, min:Number, max:Number, min2:Number, max2:Number):Number

Transfers a value from one scale to another scale, but clamps the return value within the second scale.

Parameters

value:Number — The value on the first scale.
 
min:Number — The minimum range of the first scale.
 
max:Number — The maximum range of the first scale.
 
min2:Number — The minimum range of the second scale.
 
max2:Number — The maximum range of the second scale.

Returns
Number — The scaled and clamped value.
setCamera()method 
public static function setCamera(x:Number = 0, y:Number = 0):void

Sets the camera position.

Parameters

x:Number (default = 0) — X position.
 
y:Number (default = 0) — Y position.

shuffle()method 
public static function shuffle(a:Object):void

Shuffles the elements in the array.

Parameters

a:Object — The Object to shuffle (an Array or Vector).

sign()method 
public static function sign(value:Number):int

Finds the sign of the provided value.

Parameters

value:Number — The Number to evaluate.

Returns
int — 1 if value > 0, -1 if value < 0, and 0 when value == 0.
sort()method 
public static function sort(object:Object, ascending:Boolean = true):void

Sorts the elements in the array.

Parameters

object:Object — The Object to sort (an Array or Vector).
 
ascending:Boolean (default = true) — If it should be sorted ascending (true) or descending (false).

sortBy()method 
public static function sortBy(object:Object, property:String, ascending:Boolean = true):void

Sorts the elements in the array by a property of the element.

Parameters

object:Object — The Object to sort (an Array or Vector).
 
property:String — The numeric property of object's elements to sort by.
 
ascending:Boolean (default = true) — If it should be sorted ascending (true) or descending (false).

stepTowards()method 
public static function stepTowards(object:Object, x:Number, y:Number, distance:Number = 1):void

Steps the object towards a point.

Parameters

object:Object — Object to move (must have an x and y property).
 
x:Number — X position to step towards.
 
y:Number — Y position to step towards.
 
distance:Number (default = 1) — The distance to step (will not overshoot target).

swap()method 
public static function swap(current:*, a:*, b:*):*

Swaps the current item between a and b. Useful for quick state/string/value swapping.

Parameters

current:* — The currently selected item.
 
a:* — Item a.
 
b:* — Item b.

Returns
* — Returns a if current is b, and b if current is a.
timeFlag()method 
public static function timeFlag():uint

Sets a time flag.

Returns
uint — Time elapsed (in milliseconds) since the last time flag was set.
tween()method 
public static function tween(object:Object, values:Object, duration:Number, options:Object = null):MultiVarTween

Tweens numeric public properties of an Object. Shorthand for creating a MultiVarTween tween, starting it and adding it to a Tweener.

Parameters

object:Object — The object containing the properties to tween.
 
values:Object — An object containing key/value pairs of properties and target values.
 
duration:Number — Duration of the tween.
 
options:Object (default = null) — An object containing key/value pairs of the following optional parameters: type Tween type. complete Optional completion callback function. ease Optional easer function. tweener The Tweener to add this Tween to. delay A length of time to wait before starting this tween.

Returns
MultiVarTween — The added MultiVarTween object. Example: FP.tween(object, { x: 500, y: 350 }, 2.0, { ease: easeFunction, complete: onComplete } );
watch()method 
public static function watch(... properties):void

Adds properties to watch in the console's debug panel.

Parameters

... properties — The properties (strings) to watch.

Constant Detail
VERSIONConstant
public static const VERSION:String = 1.7.2

The FlashPunk major version.