A set of functions related to angle calculations. In degrees: (down = 90, right = 0, up = -90)

Note: in Flixel 5.0.0 all angle-related tools were changed so that 0 degrees points right, instead of up

See also:

Static variables

staticread onlyTO_DEG:Float

Convert radians to degrees by multiplying it with this value.

staticread onlyTO_RAD:Float

Convert degrees to radians by multiplying it with this value.

Static methods

@:value({ AsDegrees : false })staticangleBetween(SpriteA:FlxSprite, SpriteB:FlxSprite, AsDegrees:Bool = false):Float

Find the angle between the two FlxSprite, taking their x/y and origin into account.

Parameters:

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)

@:value({ AsDegrees : false })staticangleBetweenMouse(Object:FlxObject, AsDegrees:Bool = false):Float

Find the angle between an FlxSprite and the mouse, taking their screen x/y and origin into account.

Parameters:

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)

@:value({ AsDegrees : false })staticangleBetweenPoint(Sprite:FlxSprite, Target:FlxPoint, AsDegrees:Bool = false):Float

Find the angle between an FlxSprite and an FlxPoint. The source sprite takes its x/y and origin into account.

Parameters:

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)

@:value({ AsDegrees : false })staticangleBetweenTouch(Object:FlxObject, Touch:FlxTouch, AsDegrees:Bool = false):Float

Find the angle between an FlxSprite and a FlxTouch, taking their screen x/y and origin into account.

Parameters:

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)

@:value({ AsDegrees : false })staticangleFromFacing(Facing:FlxDirectionFlags, AsDegrees:Bool = false):Float

Deprecated: "FlxAngle.angleFromFacing is deprecated, use flags.degrees."

Translate an object's facing to angle.

Parameters:

FacingBitmask

Bitmask from which to calculate the angle, as in FlxSprite::facing

AsDegrees

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

Returns:

The angle (in radians unless AsDegrees is true)

@:value({ asDegrees : false })staticinlineangleFromOrigin(x:Float, y:Float, asDegrees:Bool = false):Float

Calculates the angle from (0, 0) to (x, y)

Parameters:

x

The x distance from the origin

y

The y distance from the origin

asDegrees

If true, it gives the value in degrees

Returns:

The angle, either in degrees, between -180 and 180 or in radians, between -PI and PI

staticinlineasDegrees(radians:Float):Float

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

Parameters:

radians

The value in radians

Returns:

Degrees

staticinlineasRadians(degrees:Float):Float

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

Parameters:

degrees

The value in degrees

Returns:

Radians

staticinlinedegreesBetween(SpriteA:FlxSprite, SpriteB:FlxSprite):Float

Find the angle (in degrees) between the two FlxSprite, taking their x/y and origin into account.

Parameters:

SpriteA

The FlxSprite to test from

SpriteB

The FlxSprite to test to

Returns:

The angle in degrees

Available since

5.0.0

.

staticinlinedegreesBetweenMouse(Object:FlxObject):Float

Find the angle (in degrees) between an FlxSprite and the mouse, taking their screen x/y and origin into account.

Parameters:

Object

The FlxObject to test from

Returns:

The angle in degrees

Available since

5.0.0

.

staticinlinedegreesBetweenPoint(Sprite:FlxSprite, Target:FlxPoint):Float

Find the angle (in degrees) between an FlxSprite and an FlxPoint. The source sprite takes its x/y and origin into account.

Parameters:

Sprite

The FlxSprite to test from

Target

The FlxPoint to angle the FlxSprite towards

Returns:

The angle in degrees

Available since

5.0.0

.

staticinlinedegreesBetweenTouch(Object:FlxObject, Touch:FlxTouch):Float

Find the angle (in degrees) between an FlxSprite and a FlxTouch, taking their screen x/y and origin into account.

Parameters:

Object

The FlxObject to test from

Touch

The FlxTouch to test to

Returns:

The angle in degrees

Available since

5.0.0

.

staticinlinedegreesFromOrigin(x:Float, y:Float):Float

Calculates the angle from (0, 0) to (x, y), in degrees

Parameters:

x

The x distance from the origin

y

The y distance from the origin

Returns:

The angle in degrees between -180 to 180

staticgetCartesianCoords(Radius:Float, Angle:Float, ?point:FlxPoint):FlxPoint

Deprecated: "FlxAngle.getCartesianCoords is deprecated, use FlxVector.setPolarDegrees"

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

Parameters:

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

staticgetPolarCoords(X:Float, Y:Float, ?point:FlxPoint):FlxPoint

Deprecated: "FlxAngle.getCartesianCoords is deprecated, use FlxPoint"

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

Parameters:

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, y = Angle (degrees))

staticinlineradiansBetween(SpriteA:FlxSprite, SpriteB:FlxSprite):Float

Find the angle (in radians) between the two FlxSprite, taking their x/y and origin into account.

Parameters:

SpriteA

The FlxSprite to test from

SpriteB

The FlxSprite to test to

Returns:

The angle in radians

Available since

5.0.0

.

staticinlineradiansBetweenMouse(Object:FlxObject):Float

Find the angle (in radians) between an FlxSprite and the mouse, taking their screen x/y and origin into account.

Parameters:

Object

The FlxObject to test from

Returns:

The angle in radians

Available since

5.0.0

.

staticinlineradiansBetweenPoint(Sprite:FlxSprite, Target:FlxPoint):Float

Find the angle (in radians) between an FlxSprite and an FlxPoint. The source sprite takes its x/y and origin into account.

Parameters:

Sprite

The FlxSprite to test from

Target

The FlxPoint to angle the FlxSprite towards

Returns:

The angle in radians

Available since

5.0.0

.

staticinlineradiansBetweenTouch(Object:FlxObject, Touch:FlxTouch):Float

Find the angle (in radians) between an FlxSprite and a FlxTouch, taking their screen x/y and origin into account.

Parameters:

Object

The FlxObject to test from

Touch

The FlxTouch to test to

Returns:

The angle in radians

Available since

5.0.0

.

staticinlineradiansFromOrigin(x:Float, y:Float):Float

Calculates the angle from (0, 0) to (x, y), in radians

Parameters:

x

The x distance from the origin

y

The y distance from the origin

Returns:

The angle in radians between -PI to PI

staticsinCosGenerator(length:Dynamic, sinAmplitude:Dynamic, cosAmplitude:Dynamic, frequency:Dynamic):Dynamic

Generate a sine and cosine table during compilation

The parameters allow you to specify the length, amplitude and frequency of the wave. You have to call this function with constant parameters and either use it on your own or assign it to FlxAngle.sincos

Parameters:

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 cosine/sine table in a FlxSinCos

staticwrapAngle(angle:Float):Float

Keeps an angle value between -180 and +180 by wrapping it e.g an angle of +270 will be converted to -90 Should be called whenever the angle is updated on a FlxSprite to stop it from going insane.

Parameters:

angle

The angle value to check

Returns:

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