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.
Static variables
staticinlineread onlyANY:FlxDirectionFlags = FlxDirectionFlags.ANY
Special-case constant meaning any direction, used mainly by allowCollisions
and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.ANY
directly.
staticinlineread onlyCEILING:FlxDirectionFlags = FlxDirectionFlags.CEILING
Special-case constant meaning up, used mainly by allowCollisions
and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.CEILING
directly.
staticinlineread onlyDOWN:FlxDirectionFlags = FlxDirectionFlags.DOWN
Generic value for "down". Used by facing
, allowCollisions
, and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.DOWN
directly.
staticinlineread onlyFLOOR:FlxDirectionFlags = FlxDirectionFlags.FLOOR
Special-case constant meaning down, used mainly by allowCollisions
and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.FLOOR
directly.
staticinlineread onlyLEFT:FlxDirectionFlags = FlxDirectionFlags.LEFT
Generic value for "left". Used by facing
, allowCollisions
, and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.LEFT
directly.
staticinlineread onlyNONE:FlxDirectionFlags = FlxDirectionFlags.NONE
Special-case constant meaning no collisions, used mainly by allowCollisions
and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.NONE
directly.
staticinlineread onlyRIGHT:FlxDirectionFlags = FlxDirectionFlags.RIGHT
Generic value for "right". Used by facing
, allowCollisions
, and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.RIGHT
directly.
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:FlxDirectionFlags = FlxDirectionFlags.UP
Generic value for "up". Used by facing
, allowCollisions
, and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.UP
directly.
staticinlineread onlyWALL:FlxDirectionFlags = FlxDirectionFlags.WALL
Special-case constant meaning only the left and right sides, used mainly by allowCollisions
and touching
.
Note: This exists for backwards compatibility, prefer using FlxDirectionFlags.WALL
directly.
staticdefaultPixelPerfectPosition:Bool = false
Default value for FlxObject
's pixelPerfectPosition
var.
Static methods
staticupdateTouchingFlags(Object1:FlxObject, Object2:FlxObject):Bool
staticupdateTouchingFlagsX(Object1:FlxObject, Object2:FlxObject):Bool
Constructor
Variables
read onlyacceleration:FlxPoint
How fast the speed of this object is changing (in pixels per second). Useful for smooth movement and gravity.
allowCollisions:FlxDirectionFlags = 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!
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 == NONE
.
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
ANY
or NONE
in the case of tiles in FlxTilemap
).
4.2.0
.debugBoundingBoxColorSolid:FlxColor = FlxColor.RED
Color used for the debug rect if allowCollisions == ANY
.
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."
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
.
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!
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:FlxDirectionFlags = 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!
wasTouching:FlxDirectionFlags = 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!
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
getRotatedBounds(?newRect:FlxRect):FlxRect
Calculates the smallest globally aligned bounding box that encompasses this
object's width and height, at its current rotation.
Note, if called on a FlxSprite
, the origin is used, but scale and offset are ignored.
Use getScreenBounds
to use these properties.
Parameters:
newRect | The optional output |
---|
Returns:
A globally aligned FlxRect
that fully contains the input object's width and height.
4.11.0
.getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint
Call this function to figure out the on-screen position of the object.
Parameters:
Point | Takes a |
---|---|
Camera | Specify which game camera you want.
If |
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 |
---|
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:FlxDirectionFlags):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. |
---|
Returns:
Whether the object is touching an object in (any of) the specified direction(s) this frame.
inlinejustTouched(Direction:FlxDirectionFlags):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. |
---|
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 |
Camera | Specify which game camera you want.
If |
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 |
Camera | Specify which game camera you want.
If |
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 |
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. |
inlinescreenCenter(axes:FlxAxes = XY):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 (e.g. |
---|
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 |