class flixel.FlxObject extends FlxBasic
Available on all platforms
Sub classes | ||||||||||
![]() | FlxClickArea, FlxTile, FlxTilemap, FlxSprite |
|
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 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.
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.
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)!
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.
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 ignoreDrawDebug:Bool
Setting this to true will prevent the object from appearing * when FlxG.debugger.drawDebug is true.
Important variable for collision processing. * By default this value is set automatically during preUpdate().
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 maxVelocity:FlxPoint
If you are using acceleration, you can use maxVelocity with it * to cap the speed automatically (very useful!).
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.
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).
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.
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 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!
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. |
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()!
Rarely called, and in this case just increments the visible objects count and calls drawDebug() if necessary.
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. |