class flixel.util.FlxAngle

Available on all platforms

A set of functions related to angle calculations.

Class Fields

static var TO_DEG:Float

Convert radians to degrees by multiplying it with this value.

static var TO_RAD:Float

Convert degrees to radians by multiplying it with this value.

static var cosTable:Array<Float>

Use this to access the cos-table generated via sinCosGenerator().

static var sinTable:Array<Float>

Use this to access the sin-table generated via sinCosGenerator().

static function angleBetween(SpriteA:FlxSprite, SpriteB:FlxSprite, ?AsDegrees:Bool = false):Float

Find the angle (in radians) between the two FlxSprite, taking their x/y and origin into account. * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * *

SpriteA

The FlxSprite to test from *

SpriteB

The FlxSprite to test to *

AsDegrees

If you need the value in degrees instead of radians, set to true *

returns

The angle (in radians unless asDegrees is true)

static function angleBetweenMouse(Object:FlxObject, ?AsDegrees:Bool = false):Float

Find the angle (in radians) between an FlxSprite and the mouse, taking their x/y and origin into account. * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * *

Object

The FlxObject to test from *

AsDegrees

If you need the value in degrees instead of radians, set to true *

returns

The angle (in radians unless AsDegrees is true)

static function angleBetweenPoint(Sprite:FlxSprite, Target:FlxPoint, ?AsDegrees:Bool = false):Float

Find the angle (in radians) between an FlxSprite and an FlxPoint. The source sprite takes its x/y and origin into account. * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * *

Sprite

The FlxSprite to test from *

Target

The FlxPoint to angle the FlxSprite towards *

AsDegrees

If you need the value in degrees instead of radians, set to true *

returns

The angle (in radians unless AsDegrees is true)

static function angleBetweenTouch(Object:FlxObject, Touch:FlxTouch, ?AsDegrees:Bool = false):Float

Find the angle (in radians) between an FlxSprite and a FlxTouch, taking their x/y and origin into account. * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * *

Object

The FlxObject to test from *

Touch

The FlxTouch to test to *

AsDegrees

If you need the value in degrees instead of radians, set to true *

returns

The angle (in radians unless AsDegrees is true)

static function angleLimit(angle:Int, min:Int, max:Int):Int

Keeps an angle value between the given min and max values * *

angle

The angle value to check. Must be between -180 and +180 *

min

The minimum angle that is allowed (must be -180 or greater) *

max

The maximum angle that is allowed (must be 180 or less) * *

returns

The new angle value, returns the same as the input angle if it was within bounds

static function asDegrees(radians:Float):Float

Converts a Radian value into a Degree * Converts the radians value into degrees and returns * *

radians

The value in radians *

returns

Degrees

static function asRadians(degrees:Float):Float

Converts a Degrees value into a Radian * Converts the degrees value into radians and returns * *

degrees

The value in degrees *

returns

Radians

static function getAngle(Point1:FlxPoint, Point2:FlxPoint):Float

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

Point1

The X coordinate of the point. *

Point2

The Y coordinate of the point. *

returns

The angle in degrees, between -180 and 180.

static function getCartesianCoords(Radius:Float, Angle:Float, ?point:FlxPoint = null):FlxPoint

Convert polar coordinates (radius + angle) to cartesian coordinates (x + y) * *

Radius

The radius *

Angle

The angle, in degrees *

point

Optional FlxPoint if you don't want a new one created *

returns

The point in cartesian coords

static function getPolarCoords(X:Float, Y:Float, ?point:FlxPoint = null):FlxPoint

Convert cartesian coordinates (x + y) to polar coordinates (radius + angle) * *

X

x position *

Y

y position *

point

Optional FlxPoint if you don't want a new one created *

returns

The point in polar coords (x = Radius (degrees), y = Angle)

static function rotatePoint(X:Float, Y:Float, PivotX:Float, PivotY:Float, Angle:Float, ?point:FlxPoint = null):FlxPoint

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

X

The X coordinate of the point you want to rotate. *

Y

The Y coordinate of the point you want to rotate. *

PivotX

The X coordinate of the point you want to rotate around. *

PivotY

The Y coordinate of the point you want to rotate around. *

Angle

Rotate the point by this many degrees. *

Point

Optional FlxPoint to store the results in. *

returns

A FlxPoint containing the coordinates of the rotated point.

static function sinCosGenerator(length:Int, ?sinAmplitude:Float = 1.0f, ?cosAmplitude:Float = 1.0f, ?frequency:Float = 1.0f):Void

Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at * * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function * you should get the results via sinTable and cosTable. This generator is fast enough to be used in real-time. * * @see getSinTable * @see getCosTable

length

The length of the wave *

sinAmplitude

The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value *

cosAmplitude

The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value *

frequency

The frequency of the sine and cosine table data *

returns

Returns the sine table *

static function wrapAngle(angle:Float):Int

Keeps an angle value between -180 and +180 * Should be called whenever the angle is updated on a FlxSprite to stop it from going insane. * *

angle

The angle value to check * *

returns

The new angle value, returns the same as the input angle if it was within bounds