This is the base class for most of the display objects (FlxSprite, FlxText, etc). It includes some basic attributes about game objects, basic state information, sizes, scrolling, and basic physics and motion.

Constructor

new(X:Float = 0, Y:Float = 0, Width:Float = 0, Height:Float = 0)

Parameters:

X

The X-coordinate of the point in space.

Y

The Y-coordinate of the point in space.

Width

Desired width of the rectangle.

Height

Desired height of the rectangle.

Variables

read onlyacceleration:FlxPoint

How fast the speed of this object is changing (in pixels per second). Useful for smooth movement and gravity.

allowCollisions:Int = ANY

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions. Use bitwise operators to check the values stored here. Useful for things like one-way platforms (e.g. allowCollisions = UP;). The accessor "solid" just flips this variable between NONE and ANY.

angle:Float = 0

Set the angle (in degrees) of a sprite to rotate it. WARNING: rotating sprites decreases their rendering performance by a factor of ~10x when using blitting!

angularAcceleration:Float = 0

How fast the spin speed should change (in degrees per second).

angularDrag:Float = 0

Like drag but for spinning.

angularVelocity:Float = 0

This is how fast you want this sprite to spin (in degrees per second).

collisonXDrag:Bool = true

Whether this sprite is dragged along with the horizontal movement of objects it collides with (makes sense for horizontally-moving platforms in platformers for example).

debugBoundingBoxColor:Null<FlxColor> = null

Overriding this will force a specific color to be used for debug rect (ignoring any of the other debug bounding box colors specified).

debugBoundingBoxColorNotSolid:FlxColor = FlxColor.BLUE

Color used for the debug rect if allowCollisions == FlxObject.NONE.

Available since

4.2.0

.

debugBoundingBoxColorPartial:FlxColor = FlxColor.GREEN

Color used for the debug rect if this object collides partially (immovable in the case of FlxObject, or allowCollisions not equal to FlxObject.ANY or FlxObject.NONE in the case of tiles in FlxTilemap).

Available since

4.2.0

.

debugBoundingBoxColorSolid:FlxColor = FlxColor.RED

Color used for the debug rect if allowCollisions == FlxObject.ANY.

Available since

4.2.0

.

read onlydrag:FlxPoint

This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.

elasticity:Float = 0

The bounciness of this object. Only affects collisions. Default value is 0, or "not bouncy at all."

health:Float = 1

Handy for storing health percentage or armor points or whatever.

height:Float

The height of this object's hitbox. For sprites, use offset to control the hitbox position.

ignoreDrawDebug:Bool = false

Setting this to true will prevent the object from appearing when FlxG.debugger.drawDebug is true.

immovable:Bool = false

Whether an object will move/alter position after a collision.

read onlylast:FlxPoint

Important variable for collision processing. By default this value is set automatically during at the start of update().

mass:Float = 1

The virtual mass of the object. Default value is 1. Currently only used with elasticity during collision resolution. Change at your own risk; effects seem crazy unpredictable so far!

maxAngular:Float = 10000

Use in conjunction with angularAcceleration for fluid spin speed control.

read onlymaxVelocity:FlxPoint

If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).

moves:Bool = true

Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()). FlxObject and FlxSprite default to true. FlxText, FlxTileblock and FlxTilemap default to false.

path:FlxPath = null

The path this object follows. Not initialized by default. Assign a new FlxPath() object and start() it if you want to this object to follow a path. Set path to null again to stop following the path. See flixel.util.FlxPath for more info and usage examples.

pixelPerfectPosition:Bool = true

Whether or not the position of this object should be rounded before any draw() or collision checking.

pixelPerfectRender:Null<Bool>

Whether or not the coordinates should be rounded during rendering. Does not affect copyPixels(), which can only render on whole pixels. Defaults to the camera's global pixelPerfectRender value, but overrides that value if not equal to null.

read onlyscrollFactor:FlxPoint

Controls how much this object is affected by camera scrolling. 0 = no movement (e.g. a background layer), 1 = same movement speed as the foreground. Default value is (1,1), except for UI elements like FlxButton where it's (0,0).

solid:Bool

Whether the object collides or not. For more control over what directions the object will collide from, use collision constants (like LEFT, FLOOR, etc) to set the value of allowCollisions directly.

touching:Int = NONE

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts. Use bitwise operators to check the values stored here, or use isTouching(), justTouched(), etc. You can even use them broadly as boolean values if you're feeling saucy!

read onlyvelocity:FlxPoint

The basic speed of this object (in pixels per second).

wasTouching:Int = NONE

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step. Use bitwise operators to check the values stored here, or use isTouching(), justTouched(), etc. You can even use them broadly as boolean values if you're feeling saucy!

width:Float

The width of this object's hitbox. For sprites, use offset to control the hitbox position.

x:Float = 0

X position of the upper left corner of this object in world space.

y:Float = 0

Y position of the upper left corner of this object in world space.

Methods

destroy():Void

WARNING: A destroyed FlxBasic can't be used anymore. It may even cause crashes if it is still part of a group or state. You may want to use kill() instead if you want to disable the object temporarily only and revive() it later.

This function is usually not called manually (Flixel calls it automatically during state switches for all add()ed objects).

Override this function to null out variables manually or call destroy() on class members if necessary. Don't forget to call super.destroy()!

draw():Void

Rarely called, and in this case just increments the visible objects count and calls drawDebug() if necessary.

drawDebugOnCamera(camera:FlxCamera):Void

Override this function to draw custom "debug mode" graphics to the specified camera while the debugger's drawDebug mode is toggled on.

Parameters:

Camera

Which camera to draw the debug visuals to.

getMidpoint(?point:FlxPoint):FlxPoint

Retrieve the midpoint of this object in world coordinates.

Parameters:

point

Allows you to pass in an existing FlxPoint object if you're so inclined. Otherwise a new one is created.

Returns:

A FlxPoint object containing the midpoint of this object in world coordinates.

getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint

Call this function to figure out the on-screen position of the object.

Parameters:

Point

Takes a FlxPoint object and assigns the post-scrolled X and Y values of this object to it.

Camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.

hurt(Damage:Float):Void

Reduces the health variable of this object by the amount specified in Damage. Calls kill() if health drops to or below zero.

Parameters:

Damage

How much health to take away (use a negative number to give a health bonus).

inlineinWorldBounds():Bool

Check and see if this object is currently within the world bounds - useful for killing objects that get too far away.

Returns:

Whether the object is within the world bounds or not.

isOnScreen(?Camera:FlxCamera):Bool

Check and see if this object is currently on screen.

Parameters:

Camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

Whether the object is on screen or not.

isPixelPerfectRender(?Camera:FlxCamera):Bool

Check if object is rendered pixel perfect on a specific camera.

inlineisTouching(Direction:Int):Bool

Handy function for checking if this object is touching a particular surface. Be sure to check it before calling super.update(), as that will reset the flags.

Parameters:

Direction

Any of the collision flags (e.g. LEFT, FLOOR, etc).

Returns:

Whether the object is touching an object in (any of) the specified direction(s) this frame.

inlinejustTouched(Direction:Int):Bool

Handy function for checking if this object is just landed on a particular surface. Be sure to check it before calling super.update(), as that will reset the flags.

Parameters:

Direction

Any of the collision flags (e.g. LEFT, FLOOR, etc).

Returns:

Whether the object just landed on (any of) the specified surface(s) this frame.

overlaps(ObjectOrGroup:FlxBasic, InScreenSpace:Bool = false, ?Camera:FlxCamera):Bool

Checks to see if some FlxObject overlaps this FlxObject or FlxGroup. If the group has a LOT of things in it, it might be faster to use FlxG.overlap(). WARNING: Currently tilemaps do NOT support screen space overlap checks!

Parameters:

ObjectOrGroup

The object or group being tested.

InScreenSpace

Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."

Camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

Whether or not the two objects overlap.

overlapsAt(X:Float, Y:Float, ObjectOrGroup:FlxBasic, InScreenSpace:Bool = false, ?Camera:FlxCamera):Bool

Checks to see if this FlxObject were located at the given position, would it overlap the FlxObject or FlxGroup? This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size into account. WARNING: Currently tilemaps do NOT support screen space overlap checks!

Parameters:

X

The X position you want to check. Pretends this object (the caller, not the parameter) is located here.

Y

The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.

ObjectOrGroup

The object or group being tested.

InScreenSpace

Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."

Camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

Whether or not the two objects overlap.

overlapsPoint(point:FlxPoint, InScreenSpace:Bool = false, ?Camera:FlxCamera):Bool

Checks to see if a point in 2D world space overlaps this FlxObject.

Parameters:

Point

The point in world space you want to check.

InScreenSpace

Whether to take scroll factors into account when checking for overlap.

Camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

Whether or not the point overlaps this object.

reset(X:Float, Y:Float):Void

Handy function for reviving game objects. Resets their existence flags and position.

Parameters:

X

The new X position of this object.

Y

The new Y position of this object.

screenCenter(?axes:FlxAxes):FlxObject

Centers this FlxObject on the screen, either by the x axis, y axis, or both.

Parameters:

axes

On what axes to center the object - default is FlxAxes.XY / both.

Returns:

This FlxObject for chaining

setPosition(X:Float = 0, Y:Float = 0):Void

Helper function to set the coordinates of this object. Handy since it only requires one line of code.

Parameters:

X

The new x position

Y

The new y position

setSize(Width:Float, Height:Float):Void

Shortcut for setting both width and Height.

Parameters:

Width

The new hitbox width.

Height

The new hitbox height.

toString():String

Convert object to readable string name. Useful for debugging, save games, etc.

update(elapsed:Float):Void

Override this function to update your class's position and appearance. This is where most of your game rules and behavioral code will go.

Static variables

staticinlineread onlyANY:Int = LEFT | RIGHT | UP | DOWN

Special-case constant meaning any direction, used mainly by allowCollisions and touching.

staticinlineread onlyCEILING:Int = UP

Special-case constant meaning up, used mainly by allowCollisions and touching.

staticinlineread onlyDOWN:Int = 0x1000

Generic value for "down". Used by facing, allowCollisions, and touching.

staticinlineread onlyFLOOR:Int = DOWN

Special-case constant meaning down, used mainly by allowCollisions and touching.

staticinlineread onlyLEFT:Int = 0x0001

Generic value for "left". Used by facing, allowCollisions, and touching.

staticinlineread onlyNONE:Int = 0x0000

Special-case constant meaning no collisions, used mainly by allowCollisions and touching.

staticinlineread onlyRIGHT:Int = 0x0010

Generic value for "right". Used by facing, allowCollisions, and touching.

staticSEPARATE_BIAS:Float = 4

This value dictates the maximum number of pixels two objects have to intersect before collision stops trying to separate them. Don't modify this unless your objects are passing through each other.

staticinlineread onlyUP:Int = 0x0100

Generic value for "up". Used by facing, allowCollisions, and touching.

staticinlineread onlyWALL:Int = LEFT | RIGHT

Special-case constant meaning only the left and right sides, used mainly by allowCollisions and touching.

staticdefaultPixelPerfectPosition:Bool = false

Default value for FlxObject's pixelPerfectPosition var.

Static methods

staticseparate(Object1:FlxObject, Object2:FlxObject):Bool

The main collision resolution function in Flixel.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched and were separated.

staticseparateX(Object1:FlxObject, Object2:FlxObject):Bool

The X-axis component of the object separation process.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched and were separated along the X axis.

staticseparateY(Object1:FlxObject, Object2:FlxObject):Bool

The Y-axis component of the object separation process.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched and were separated along the Y axis.

staticupdateTouchingFlags(Object1:FlxObject, Object2:FlxObject):Bool

Similar to separate(), but only checks whether any overlap is found and updates the touching flags of the input objects, but no separation is performed.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched.

staticupdateTouchingFlagsX(Object1:FlxObject, Object2:FlxObject):Bool

Checking overlap and updating touching variables, X-axis part used by updateTouchingFlags.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched along the X axis.

staticupdateTouchingFlagsY(Object1:FlxObject, Object2:FlxObject):Bool

Checking overlap and updating touching variables, Y-axis part used by updateTouchingFlags.

Parameters:

Object1

Any FlxObject.

Object2

Any other FlxObject.

Returns:

Whether the objects in fact touched along the Y axis.

Inherited Variables

Defined by FlxBasic

ID:Int = -1

IDs seem like they could be pretty useful, huh? They're not actually used for anything yet though.

active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets ot sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses FlxCamera.defaultCameras, which is a reference to FlxG.cameras.list (all cameras) by default.

exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxBasic

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().