C# Class flxSharp.flxSharp.FlxU

General purpose helper functions.
Show file Open project: jlorek/flxSharp Class Usage Examples

Public Properties

Property Type Description
Random System.Random

Public Methods

Method Description
abs ( float value ) : float

Calculate the absolute value of a number.

bound ( float value, float min, float max ) : float

Bound a number by a minimum and maximum. Ensures that this number is no smaller than the minimum, and no larger than the maximum.

ceil ( float value ) : float

Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.

compareClassNames ( object object1, object object2 ) : bool

Check to see if two objects have the same class name.

computeVelocity ( float velocity, float acceleration, float drag, float max = 10000.0f ) : float

A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.

floor ( float value ) : float

Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.

formatArray ( Array anyArray ) : string

Generate a comma-separated string from an array. Especially useful for tracing or other debug output.

formatMoney ( float amount, bool showDecimal = true, bool englishStyle = true ) : string

Automatically commas and decimals in the right places for displaying money amounts. Does not include a dollar sign or anything, so doesn't really do much if you call say String results = FlxU.formatMoney(10,false); However, very handy for displaying large sums or decimal money values.

formatTicks ( long startTicks, long endTicks ) : string

Takes two "ticks" timestamps and formats them into the number of seconds that passed as a String. Useful for logging, debugging, the watch window, or whatever else.

formatTime ( ulong seconds, bool showMS = false ) : string

Format seconds as minutes with a colon, an optionally with milliseconds too.

getClass ( string name ) : object

Look up a Class object by its string name.

getClassName ( object obj, bool simple = false ) : string

Get the String name of any Object.

getHSB ( uint color, Array result = null ) : Array

Loads an array with the HSB values of a Flash uint color. Hue is a value between 0 and 360. Saturation, Brightness and Alpha are as floating point numbers between 0 and 1.

getRGBA ( uint color, Array result = null ) : Array

Loads an array with the RGBA values of a Flash uint color. RGB values are stored 0-255. Alpha is stored as a floating point number between 0 and 1.

getRandom ( Array objects, uint startIndex, uint length ) : object

Fetch a random entry from the given array. Will return null if random selection is missing, or array has no entries. FlxG.getRandom() is deterministic and safe for use with replays/recordings. HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.

getTicks ( ) : long

Just grabs the current "ticks" or time in milliseconds that has passed since Flash Player started up. Useful for finding out how long it takes to execute specific blocks of code.

makeColor ( uint red, uint green, uint blue, float alpha = 1.0f ) : uint

Generate a Flash uint color from RGBA components.

makeColorFromHSB ( float hue, float saturation, float brightness, float alpha = 1.0f ) : uint

Generate a Flash uint color from HSB components.

max ( float number1, float number2 ) : float

Figure out which number is larger.

min ( float number1, float number2 ) : float

Figure out which number is smaller.

openURL ( string url ) : void

Opens a web page in a new tab or window. MUST be called from the UI thread or else badness.

rotatePoint ( float x, float y, float pivotX, float pivotY, float angle, FlxPoint point = null ) : FlxPoint

Rotates a point in 2D space around another point by the given angle.

round ( float value ) : float

Round to the closest whole number. E.g. round(1.7) == 2, and round(-2.3) == -2.

shuffle ( Array objects, uint howManyTimes ) : Array

Shuffles the entries in an array into a new random order. FlxG.shuffle() is deterministic and safe for use with replays/recordings. HOWEVER, FlxU.shuffle() is NOT deterministic and unsafe for use with replays/recordings.

srand ( float seed ) : float

Generates a random number based on the seed provided.

Private Methods

Method Description
getAngle ( FlxPoint point1, FlxPoint point2 ) : float

Calculates the angle between two points. 0 degrees points straight up.

getDistance ( FlxPoint point1, FlxPoint point2 ) : float

Calculate the distance between two points.

Method Details

abs() public static method

Calculate the absolute value of a number.
public static abs ( float value ) : float
value float Any number.
return float

bound() public static method

Bound a number by a minimum and maximum. Ensures that this number is no smaller than the minimum, and no larger than the maximum.
public static bound ( float value, float min, float max ) : float
value float Any number.
min float Any number.
max float Any number.
return float

ceil() public static method

Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
public static ceil ( float value ) : float
value float Any number.
return float

compareClassNames() public static method

Check to see if two objects have the same class name.
public static compareClassNames ( object object1, object object2 ) : bool
object1 object The first object you want to check.
object2 object The second object you want to check.
return bool

computeVelocity() public static method

A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
public static computeVelocity ( float velocity, float acceleration, float drag, float max = 10000.0f ) : float
velocity float Any component of velocity (e.g. 20).
acceleration float Rate at which the velocity is changing.
drag float Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
max float An absolute value cap for the velocity.
return float

floor() public static method

Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
public static floor ( float value ) : float
value float Any number.
return float

formatArray() public static method

Generate a comma-separated string from an array. Especially useful for tracing or other debug output.
public static formatArray ( Array anyArray ) : string
anyArray System.Array Any Array object.
return string

formatMoney() public static method

Automatically commas and decimals in the right places for displaying money amounts. Does not include a dollar sign or anything, so doesn't really do much if you call say String results = FlxU.formatMoney(10,false); However, very handy for displaying large sums or decimal money values.
public static formatMoney ( float amount, bool showDecimal = true, bool englishStyle = true ) : string
amount float How much moneys (in dollars, or the equivalent "main" currency - i.e. not cents).
showDecimal bool Whether to show the decimals/cents component. Default value is true.
englishStyle bool Major quantities (thousands, millions, etc) separated by commas, and decimal by a period. Default value is true.
return string

formatTicks() public static method

Takes two "ticks" timestamps and formats them into the number of seconds that passed as a String. Useful for logging, debugging, the watch window, or whatever else.
public static formatTicks ( long startTicks, long endTicks ) : string
startTicks long The first timestamp from the system.
endTicks long The second timestamp from the system.
return string

formatTime() public static method

Format seconds as minutes with a colon, an optionally with milliseconds too.
public static formatTime ( ulong seconds, bool showMS = false ) : string
seconds ulong The number of seconds (for example, time remaining, time spent, etc).
showMS bool Whether to show milliseconds after a "." as well. Default value is false.
return string

getClass() public static method

Look up a Class object by its string name.
public static getClass ( string name ) : object
name string The String name of the Class you are interested in.
return object

getClassName() public static method

Get the String name of any Object.
public static getClassName ( object obj, bool simple = false ) : string
obj object The Object object in question.
simple bool Returns only the class name, not the package or packages.
return string

getHSB() public static method

Loads an array with the HSB values of a Flash uint color. Hue is a value between 0 and 360. Saturation, Brightness and Alpha are as floating point numbers between 0 and 1.
public static getHSB ( uint color, Array result = null ) : Array
color uint The color you want to break into components.
result System.Array An optional parameter, allows you to use an array that already exists in memory to store the result.
return System.Array

getRGBA() public static method

Loads an array with the RGBA values of a Flash uint color. RGB values are stored 0-255. Alpha is stored as a floating point number between 0 and 1.
public static getRGBA ( uint color, Array result = null ) : Array
color uint The color you want to break into components.
result System.Array Results An optional parameter, allows you to use an array that already exists in memory to store the result.
return System.Array

getRandom() public static method

Fetch a random entry from the given array. Will return null if random selection is missing, or array has no entries. FlxG.getRandom() is deterministic and safe for use with replays/recordings. HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
public static getRandom ( Array objects, uint startIndex, uint length ) : object
objects System.Array A Flash array of objects.
startIndex uint Optional offset off the front of the array. Default value is 0, or the beginning of the array.
length uint Optional restriction on the number of values you want to randomly select from.
return object

getTicks() public static method

Just grabs the current "ticks" or time in milliseconds that has passed since Flash Player started up. Useful for finding out how long it takes to execute specific blocks of code.
public static getTicks ( ) : long
return long

makeColor() public static method

Generate a Flash uint color from RGBA components.
public static makeColor ( uint red, uint green, uint blue, float alpha = 1.0f ) : uint
red uint The red component, between 0 and 255.
green uint The green component, between 0 and 255.
blue uint The blue component, between 0 and 255.
alpha float How opaque the color should be, either between 0 and 1 or 0 and 255.
return uint

makeColorFromHSB() public static method

Generate a Flash uint color from HSB components.
public static makeColorFromHSB ( float hue, float saturation, float brightness, float alpha = 1.0f ) : uint
hue float A number between 0 and 360, indicating position on a color strip or wheel.
saturation float A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.
brightness float A number between 0 and 1, indicating how bright the color should be. 0 is black, 1 is full bright.
alpha float How opaque the color should be, either between 0 and 1 or 0 and 255.
return uint

max() public static method

Figure out which number is larger.
public static max ( float number1, float number2 ) : float
number1 float Any number.
number2 float Any number.
return float

min() public static method

Figure out which number is smaller.
public static min ( float number1, float number2 ) : float
number1 float Any number.
number2 float Any number.
return float

openURL() public static method

Opens a web page in a new tab or window. MUST be called from the UI thread or else badness.
public static openURL ( string url ) : void
url string The address of the web page.
return void

rotatePoint() public static method

Rotates a point in 2D space around another point by the given angle.
public static rotatePoint ( float x, float y, float pivotX, float pivotY, float angle, FlxPoint point = null ) : FlxPoint
x float The X coordinate of the point you want to rotate.
y float The Y coordinate of the point you want to rotate.
pivotX float The X coordinate of the point you want to rotate around.
pivotY float The Y coordinate of the point you want to rotate around.
angle float Rotate the point by this many degrees.
point FlxPoint Optional FlxPoint to store the results in.
return FlxPoint

round() public static method

Round to the closest whole number. E.g. round(1.7) == 2, and round(-2.3) == -2.
public static round ( float value ) : float
value float Any number.
return float

shuffle() public static method

Shuffles the entries in an array into a new random order. FlxG.shuffle() is deterministic and safe for use with replays/recordings. HOWEVER, FlxU.shuffle() is NOT deterministic and unsafe for use with replays/recordings.
public static shuffle ( Array objects, uint howManyTimes ) : Array
objects System.Array A Flash Array object containing...stuff.
howManyTimes uint How many swaps to perform during the shuffle operation. Good rule of thumb is 2-4 times as many objects are in the list.
return System.Array

srand() public static method

Generates a random number based on the seed provided.
public static srand ( float seed ) : float
seed float A number between 0 and 1, used to generate a predictable random number (very optional).
return float

Property Details

Random public static property

Random instance for shuffeling.
public static Random,System Random
return System.Random