FlixelObject
View sourceclass
org.flixelgdx.FlixelObject
The base class for all visual/spatial objects in Flixel. Extends FlixelBasic with position (FlixelObject.x, FlixelObject.y), dimensions (FlixelObject.width, FlixelObject.height), rotation (FlixelObject.angle), and a full kinematic physics model (velocity, acceleration, drag, collision flags).
Most games interact with this through FlixelSprite, which adds graphical capabilities on top of this spatial foundation.
Collision
Use Flixel.overlap() and Flixel.collide() for overlap/separation checks. The static FlixelObject.separate(FlixelObject, FlixelObject) method resolves overlaps by adjusting positions and velocities.
Constructors
FlixelObject()
Creates a new FlixelObject with the default position (0, 0) and size (0, 0).
FlixelObject(float, float)
Creates a new FlixelObject with the given position and size (0, 0).
Parameters:
| Name | Description |
|---|---|
x | The x position. |
y | The y position. |
FlixelObject(float, float, float, float)
Creates a new FlixelObject with the given position and size.
Parameters:
| Name | Description |
|---|---|
x | The x position. |
y | The y position. |
width | The width. |
height | The height. |
Fields
SEPARATE_BIAS
Maximum number of pixels two objects can intersect before FlixelObject.separate(FlixelObject, FlixelObject) gives up when using overlap checks.
lastX
X position at the start of the current frame, before motion.
lastY
Y position at the start of the current frame, before motion.
velocityX
Horizontal velocity in pixels per second.
velocityY
Vertical velocity in pixels per second.
accelerationX
Horizontal acceleration in pixels per second squared.
accelerationY
Vertical acceleration in pixels per second squared.
dragX
Deceleration applied when FlixelObject.accelerationX is zero. Only applied when greater than 0.
dragY
Deceleration applied when FlixelObject.accelerationY is zero. Only applied when greater than 0.
maxVelocityX
Maximum absolute horizontal velocity.
maxVelocityY
Maximum absolute vertical velocity.
angularVelocity
Rotational speed in degrees per second.
angularAcceleration
Rotational acceleration in degrees per second squared.
angularDrag
Rotational drag in degrees per second squared.
maxAngularVelocity
Maximum angular velocity in degrees per second.
allowCollisions
Bit field of direction flags indicating which sides allow collision. Use FlixelDirectionFlags.ANY (default) for full collision, FlixelDirectionFlags.NONE for no collision, or combine individual flags.
See Also: FlixelDirectionFlags
touching
Bit field indicating which surfaces this object is currently touching. Set by FlixelObject.separate(FlixelObject, FlixelObject) and reset at the start of each FlixelObject.update(float).
wasTouching
Copy of FlixelObject.touching from the previous frame, useful for detecting the moment an object lands (FlixelObject.justTouched(int)).
elasticity
Bounciness factor used during collision resolution. 0 means no bounce (default), 1 means fully elastic.
mass
Virtual mass used during elastic collision resolution. Default is 1. Only matters when both colliding objects have elasticity > 0.
scrollX
Parallax scroll factor on X (1 = moves with the camera like normal world objects).
scrollY
Parallax scroll factor on Y (1 = moves with the camera like normal world objects).
debugColorSolid
Color when allowCollisions == ANY and !immovable (solid). Default: red.
debugColorImmovable
Color when immovable is true or allowCollisions is partial. Default: green.
debugColorNoCollision
Color when allowCollisions == NONE. Default: blue.
debugColorOverride
If non-null, forces the debug bounding box to this color regardless of collision state.
moves
When true, FlixelObject.updateMotion(float) runs each frame.
immovable
When true, this object will not be moved by collision resolution. Other objects will still be pushed away from it.
Methods
update(float)
Updates this object's collision bookkeeping and, when FlixelObject.moves is true, calls FlixelObject.updateMotion(float).
Parameters:
| Name | Description |
|---|---|
elapsed | Seconds since the last frame. |
destroy()
getScrollX()
Parallax scroll factor on X (1 means the object moves with the camera like a normal world object).
getScrollY()
Parallax scroll factor on Y (1 means the object moves with the camera like a normal world object).
setScrollFactor(float, float)
Sets FlixelObject.getScrollX() and FlixelObject.getScrollY().
getX()
X position of the upper left corner of this object in world space.
setX(float)
Sets world X.
getY()
Y position of the upper left corner of this object in world space.
setY(float)
Sets world Y.
getWidth()
Width of this object's hitbox.
setWidth(float)
Sets hitbox width.
getHeight()
Height of this object's hitbox.
setHeight(float)
Sets hitbox height.
getAngle()
The angle in degrees of this object. Does not affect axis-aligned collision on FlixelObject.
setAngle(float)
Sets the rotation angle in degrees.
getLastX()
X position at the start of the current frame, before motion.
getLastY()
Y position at the start of the current frame, before motion.
setPosition(float, float)
Helper that sets both world coordinates.
setSize(float, float)
Shortcut for setting both FlixelObject.getWidth() and FlixelObject.getHeight().
changeX(float)
Adds dx to the current X position.
changeY(float)
Adds dy to the current Y position.
changeAngle(float)
getMidpointX()
Returns the center X coordinate of this object.
getMidpointY()
Returns the center Y coordinate of this object.
getVelocityX()
Horizontal velocity in pixels per second.
setVelocityX(float)
Sets horizontal velocity in pixels per second.
getVelocityY()
Vertical velocity in pixels per second.
setVelocityY(float)
Sets vertical velocity in pixels per second.
setVelocity(float, float)
Sets both velocity components.
getAccelerationX()
Horizontal acceleration in pixels per second squared.
setAccelerationX(float)
Sets horizontal acceleration in pixels per second squared.
getAccelerationY()
Vertical acceleration in pixels per second squared.
setAccelerationY(float)
Sets vertical acceleration in pixels per second squared.
setAcceleration(float, float)
Sets both acceleration components.
getDragX()
Deceleration applied when FlixelObject.getAccelerationX() is zero. Only applied when greater than 0.
setDragX(float)
Sets horizontal drag.
getDragY()
Deceleration applied when FlixelObject.getAccelerationY() is zero. Only applied when greater than 0.
setDragY(float)
Sets vertical drag.
setDrag(float, float)
Sets both drag components.
getMaxVelocityX()
Maximum absolute horizontal velocity.
setMaxVelocityX(float)
Sets maximum absolute horizontal velocity.
getMaxVelocityY()
Maximum absolute vertical velocity.
setMaxVelocityY(float)
Sets maximum absolute vertical velocity.
setMaxVelocity(float, float)
Sets both max velocity components.
getAngularVelocity()
Rotational speed in degrees per second.
setAngularVelocity(float)
Sets rotational speed in degrees per second.
getAngularAcceleration()
Rotational acceleration in degrees per second squared.
setAngularAcceleration(float)
Sets rotational acceleration in degrees per second squared.
getAngularDrag()
Rotational drag in degrees per second squared.
setAngularDrag(float)
Sets rotational drag in degrees per second squared.
getMaxAngularVelocity()
Maximum angular velocity in degrees per second.
setMaxAngularVelocity(float)
Sets maximum angular velocity in degrees per second.
getMoves()
When true, FlixelObject.updateMotion(float) runs each frame on FlixelObject.
setMoves(boolean)
Enables or disables automatic motion integration on FlixelObject.
getAllowCollisions()
setAllowCollisions(int)
isSolid()
Convenience accessor, returns true when allowCollisions is not FlixelDirectionFlags.NONE.
getSolid()
Returns true when allowCollisions is not FlixelDirectionFlags.NONE.
setSolid(boolean)
Sets FlixelObject.allowCollisions to ANY when solid is true, or NONE when false.
Parameters:
| Name | Description |
|---|---|
solid | Whether the object should be solid. |
getTouching()
getWasTouching()
isImmovable()
When true, this object will not be moved by collision resolution. Other objects will still be pushed away from it.
getImmovable()
Returns whether this object is immovable during collision resolution.
setImmovable(boolean)
Sets whether collision resolution may move this object.
getShakeX()
Current shake channel X (for example graphic offset or world X).
getShakeY()
Current shake channel Y.
setShake(float, float)
Sets the shake channel to absolute coordinates (typically base plus jitter).
getShakeWidth()
Width used to scale FlixelShakeUnit.FRACTION on the X axis. Values 0 or less mean the tween treats intensity like plain pixels on that axis.
getShakeHeight()
Height used to scale FlixelShakeUnit.FRACTION on the Y axis. Values 0 or less mean the tween treats intensity like plain pixels on that axis.
getElasticity()
setElasticity(float)
getMass()
setMass(float)
isTouching(int)
Returns true if this object is currently touching the given surface(s). Flags are set by Flixel.collide(...) and reset each frame.
Parameters:
| Name | Description |
|---|---|
direction | One or more direction flags ORed together. |
justTouched(int)
Returns true if this object just started touching the given surface(s) this frame (was not touching last frame).
Parameters:
| Name | Description |
|---|---|
direction | One or more direction flags ORed together. |
reset(float, float)
Resets this object to a new position, reviving it and clearing physics state.
Parameters:
| Name | Description |
|---|---|
x | New X position. |
y | New Y position. |
overlaps(FlixelObject)
Checks if this object's AABB overlaps another FlixelObject.
Parameters:
| Name | Description |
|---|---|
other | The other object. |
Returns: true if the two AABBs overlap.
overlapsPoint(float, float)
Checks if a point in world space overlaps this object's AABB.
Parameters:
| Name | Description |
|---|---|
px | X coordinate. |
py | Y coordinate. |
Returns: true if the point is inside.
inWorldBounds()
Returns true if the object is within the world bounds configured on the global manager class.
updateMotion(float)
Internal function for updating the position and speed of this object using a velocity-verlet style integration.
Parameters:
| Name | Description |
|---|---|
elapsed | Seconds elapsed since the last frame. |
computeVelocity(float, float, float, float, float)
Internal function for computing velocity after acceleration and drag.
Parameters:
| Name | Description |
|---|---|
velocity | Current velocity. |
acceleration | Acceleration to apply. |
drag | Drag to apply when acceleration is zero. |
max | Maximum allowed velocity. |
elapsed | Seconds elapsed since the last frame. |
Returns: Updated velocity.
separate(FlixelObject, FlixelObject)
Separates two overlapping objects by adjusting positions and velocities. Calls FlixelObject.separateX(FlixelObject, FlixelObject) then FlixelObject.separateY(FlixelObject, FlixelObject).
Parameters:
| Name | Description |
|---|---|
object1 | First object. |
object2 | Second object. |
Returns: true if the objects were overlapping and were separated.
separateX(FlixelObject, FlixelObject)
Separates two overlapping objects on the X axis.
Returns: true if the objects overlapped and were separated on X.
separateY(FlixelObject, FlixelObject)
Separates two overlapping objects on the Y axis.
Returns: true if the objects overlapped and were separated on Y.
computeOverlapX(FlixelObject, FlixelObject, boolean)
Computes the overlap between two objects on the X axis and updates their FlixelObject.touching flags. Returns 0 if they do not overlap or if their allowCollisions flags disallow collision on the overlapping sides.
Parameters:
| Name | Description |
|---|---|
object1 | First object. |
object2 | Second object. |
checkMaxOverlap | Whether to reject overlaps greater than combined movement + SEPARATE_BIAS. |
Returns: Signed overlap in pixels (positive means object1's right side penetrates object2's left side).
computeOverlapY(FlixelObject, FlixelObject, boolean)
Computes the overlap between two objects on the Y axis and updates their FlixelObject.touching flags. Same semantics as FlixelObject.computeOverlapX(...).
Parameters:
| Name | Description |
|---|---|
object1 | First object. |
object2 | Second object. |
checkMaxOverlap | Whether to reject overlaps greater than combined movement + SEPARATE_BIAS. |
Returns: Signed overlap in pixels (positive means object1's bottom side penetrates object2's top side).
updateTouchingFlags(FlixelObject, FlixelObject)
Checks if two objects overlap and updates their FlixelObject.touching flags without separating them.
Parameters:
| Name | Description |
|---|---|
object1 | First object. |
object2 | Second object. |
Returns: true if the two objects are touching.
getDebugX()
getDebugY()
getDebugDrawX(FlixelCamera)
getDebugDrawY(FlixelCamera)
getDebugWidth()
getDebugHeight()
getDebugBoundingBoxColor()
Returns the appropriate debug color based on collision state:
- Override color if set
- Blue when
allowCollisions == NONE - Green when
immovableor partial collision - Red (normal/solid) otherwise
setDebugBoundingBoxColor(float[])
Forces a specific debug bounding box color, overriding the automatic selection. Pass null to re-enable automatic color selection.
Parameters:
| Name | Description |
|---|---|
rgba | 4-element float array [r, g, b, a], or null. |