class flixel.FlxObject extends FlxBasic

Available on all platforms

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.

Class Fields

static var ANY:Int

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

static var CEILING:Int

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

static var DOWN:Int

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

static var FLOOR:Int

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

static var LEFT:Int

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

static var NONE:Int

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

static var RIGHT:Int

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

static var SEPARATE_BIAS:Float

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 eachother.

static var UP:Int

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

static var WALL:Int

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

static function separate(Object1:FlxObject, Object2:FlxObject):Bool

The main collision resolution function in flixel. * *

Object1

Any FlxObject. *

Object2

Any other FlxObject. *

returns

Whether the objects in fact touched and were separated.

static function separateX(Object1:FlxObject, Object2:FlxObject):Bool

The X-axis component of the object separation process. * *

Object1

Any FlxObject. *

Object2

Any other FlxObject. *

returns

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

static function separateY(Object1:FlxObject, Object2:FlxObject):Bool

The Y-axis component of the object separation process. * *

Object1

Any FlxObject. *

Object2

Any other FlxObject. *

returns

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

Instance Fields

var acceleration:FlxPoint

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

var allowCollisions:Int

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.

var angle:Float

Set the angle of a sprite to rotate it. WARNING: rotating sprites decreases rendering * performance for this sprite by a factor of 10x (in Flash target)!

var angularAcceleration:Float

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

var angularDrag:Float

Like drag but for spinning.

var angularVelocity:Float

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

var camera:FlxCamera

Gets ot sets the first camera of this object.

var 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.

var collisonXDrag:Bool

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).

var debugBoundingBoxColor:Null<Int>

Overriding this will force a specific color to be used for debug rect.

var drag:FlxPoint

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

var elasticity:Float

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

var health:Float

Handy for storing health percentage or armor points or whatever.

var height:Float

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

var ignoreDrawDebug:Bool

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

var immovable:Bool

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

var last:FlxPoint

Important variable for collision processing. * By default this value is set automatically during preUpdate().

var mass:Float

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!

var maxAngular:Float

Use in conjunction with angularAcceleration for fluid spin speed control.

var maxVelocity:FlxPoint

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

var moves:Bool

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.

var pixelPerfectRender:Bool

Whether or not the coordinates should be rounded during draw(), true by default (recommended for pixel art). * Only affects tilesheet rendering and rendering using BitmapData.draw() in blitting. * (copyPixels() only renders on whole pixels by nature). Causes draw() to be used if false, which is more expensive.

var scrollFactor: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).

var 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.

var touching:Int

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!

var velocity:FlxPoint

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

var wasTouching:Int

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!

var width:Float

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

var x:Float

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

var y:Float

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

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

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.

function destroy():Void

WARNING: This will remove this object entirely. Use kill() if you want to disable it temporarily only and reset() it later to revive it. * Override this function to null out variables manually or call destroy() on class members if necessary. Don't forget to call super.destroy()!

function draw():Void

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

function drawDebug():Void

function 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. * *

Camera

Which camera to draw the debug visuals to.

function getMidpoint(?point:FlxPoint = null):FlxPoint

Retrieve the midpoint of this object in world coordinates. * *

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.

function getScreenXY(?point:FlxPoint = null, ?Camera:FlxCamera = null):FlxPoint

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

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

Point

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

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.

function hurt(Damage:Float):Void

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

Damage

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

function inWorldBounds():Bool

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

returns

Whether the object is within the Worldbounds or not.

function isOnScreen(?Camera:FlxCamera = null):Bool

Check and see if this object is currently on screen. * *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether the object is on screen or not.

function isTouching(Direction:Int):Bool

Handy function for checking if this object is touching a particular surface. * *

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.

function justTouched(Direction:Int):Bool

Handy function for checking if this object is just landed on a particular surface. * *

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.

function overlaps(ObjectOrGroup:FlxBasic, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):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.overlaps(). WARNING: Currently tilemaps do NOT support screen space overlap checks! * *

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the two objects overlap.

function overlapsAt(X:Float, Y:Float, ObjectOrGroup:FlxBasic, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):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! * *

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the two objects overlap.

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

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

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the point overlaps this object.

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

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

X

The new X position of this object. *

Y

The new Y position of this object.

function 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. * *

X

The new x position *

Y

The new y position

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

Shortcut for setting both width and Height. * *

Width

The new sprite width. *

Height

The new sprite height.

function toString():String

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

function update():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.