C# Class flxSharp.flxSharp.FlxObject

This is the base class for most of the display objects (FlxSprite, FlxText, etc). It includes some basic attributes about game objects, including retro-style flickering, basic state information, sizes, scrolling, and basic physics and motion.
Inheritance: FlxBasic
Datei anzeigen Open project: jlorek/flxSharp Class Usage Examples

Public Properties

Property Type Description
Acceleration FlxPoint
Drag FlxPoint
MaxVelocity FlxPoint
ScrollFactor FlxPoint
Velocity FlxPoint

Protected Properties

Property Type Description
PZero FlxPoint
_flicker bool
_flickerTimer float
_pathInc int
_pathMode uint
_pathNodeIndex int
_pathRotate bool
_tagPoint FlxPoint
_tagRect FlxRect

Public Methods

Method Description
FlxObject ( float x, float y, float width, float height ) : System

Instantiates a FlxObject.

destroy ( ) : void

Override this function to null out variables or manually 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.

drawDebug ( FlxCamera Camera = null ) : void

#flx - Not yet implemented / missing FlxG.flashGfx for direct drawing (draw on immovable debug overlay?)

flicker ( float duration = 1.0f ) : void

Tells this object to flicker, retro-style. Pass a negative value to flicker forever.

followPath ( FlxPath path, float speed = 100, uint mode = PathForward, bool autoRotate = false ) : void

Call this function to give this object a path to follow. If the path does not have at least one node in it, this function will log a warning message and return.

getMidpoint ( FlxPoint point = null ) : FlxPoint

Retrieve the midpoint of this object in world coordinates.

getScreenXY ( FlxPoint point = null, FlxCamera camera = null ) : FlxPoint

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

hurt ( float damage ) : void

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

isTouching ( uint direction ) : bool

Handy function for checking if this object is touching a particular surface. For slightly better performance you can just & the value directly into touching. However, this method is good for readability and accessibility.

justTouched ( uint direction ) : bool

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

onScreen ( FlxCamera camera = null ) : bool

Check and see if this object is currently on screen.

overlaps ( FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = 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!

overlapsAt ( float x, float y, FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = 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!

overlapsPoint ( FlxPoint point, bool inScreenSpace = false, FlxCamera camera = null ) : bool

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

postUpdate ( ) : void

Post-update is called right after update() on each object in the game loop. In FlxObject this function handles integrating the objects motion based on the velocity and acceleration settings, and tracking/clearing the touching flags.

preUpdate ( ) : void

Pre-update is called right before update() on each object in the game loop. In FlxObject it controls the flicker timer, tracking the last coordinates for collision purposes, and checking if the object is moving along a path or not.

reset ( float x, float y ) : void

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

separate ( FlxObject objectOne, FlxObject objectTwo ) : bool

The main collision resolution function in flixel.

separateX ( FlxObject objectOne, FlxObject objectTwo ) : bool

The X-axis component of the object separation process.

separateY ( FlxObject objectOne, FlxObject objectTwo ) : bool

The Y-axis component of the object separation process.

stopFollowingPath ( bool destroyPath = false ) : void

Tells this object to stop following the path its on.

update ( ) : void

flx# - ? method not present in flixel

Protected Methods

Method Description
advancePath ( bool snap = true ) : FlxPoint

Internal function that decides what node in the path to aim for next based on the behavior flags.

updateMotion ( ) : void

Internal function for updating the position and speed of this object. Useful for cases when you need to update this but are buried down in too many supers. Does a slightly fancier-than-normal integration to help with higher fidelity framerate-independenct motion.

updatePathMotion ( ) : void

Internal function for moving the object along the path. Generally this function is called automatically by preUpdate(). The first half of the function decides if the object can advance to the next node in the path, while the second half handles actually picking a velocity toward the next node.

Method Details

FlxObject() public method

Instantiates a FlxObject.
public FlxObject ( float x, float y, float width, float height ) : System
x float X-coordinate of the object in space.
y float y-coordinate of the object in space.
width float Desired width of the rectangle.
height float Desired height of the rectangle.
return System

advancePath() protected method

Internal function that decides what node in the path to aim for next based on the behavior flags.
protected advancePath ( bool snap = true ) : FlxPoint
snap bool ?
return FlxPoint

destroy() public method

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

draw() public method

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

drawDebug() public method

#flx - Not yet implemented / missing FlxG.flashGfx for direct drawing (draw on immovable debug overlay?)
public drawDebug ( FlxCamera Camera = null ) : void
Camera FlxCamera Which Camera - currently only one exists
return void

flicker() public method

Tells this object to flicker, retro-style. Pass a negative value to flicker forever.
public flicker ( float duration = 1.0f ) : void
duration float How many seconds to flicker for.
return void

followPath() public method

Call this function to give this object a path to follow. If the path does not have at least one node in it, this function will log a warning message and return.
public followPath ( FlxPath path, float speed = 100, uint mode = PathForward, bool autoRotate = false ) : void
path FlxPath The FlxPath you want this object to follow.
speed float How fast to travel along the path in pixels per second.
mode uint Optional, controls the behavior of the object following the path using the path behavior constants. Can use multiple flags at once, for example PATH_YOYO|PATH_HORIZONTAL_ONLY will make an object move back and forth along the X axis of the path only.
autoRotate bool Automatically point the object toward the next node. Assumes the graphic is pointing upward. Default behavior is false, or no automatic rotation.
return void

getMidpoint() public method

Retrieve the midpoint of this object in world coordinates.
public getMidpoint ( FlxPoint point = null ) : FlxPoint
point FlxPoint Allows you to pass in an existing FlxPoint object if you're so inclined. Otherwise a new one is created.
return FlxPoint

getScreenXY() public method

Call this function to figure out the on-screen position of the object.
public getScreenXY ( FlxPoint point = null, FlxCamera camera = null ) : FlxPoint
point FlxPoint Takes a FlxPoint object and assigns the post-scrolled X and Y values of this object to it.
camera FlxCamera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
return FlxPoint

hurt() public method

Reduces the "health" variable of this sprite by the amount specified in Damage. Calls kill() if health drops to or below zero.
public hurt ( float damage ) : void
damage float How much health to take away (use a negative number to give a health bonus).
return void

isTouching() public method

Handy function for checking if this object is touching a particular surface. For slightly better performance you can just & the value directly into touching. However, this method is good for readability and accessibility.
public isTouching ( uint direction ) : bool
direction uint Any of the collision flags (e.g. LEFT, FLOOR, etc).
return bool

justTouched() public method

Handy function for checking if this object is just landed on a particular surface.
public justTouched ( uint direction ) : bool
direction uint Any of the collision flags (e.g. LEFT, FLOOR, etc).
return bool

onScreen() public method

Check and see if this object is currently on screen.
public onScreen ( FlxCamera camera = null ) : bool
camera FlxCamera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
return bool

overlaps() public method

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!
public overlaps ( FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = null ) : bool
objectOrGroup FlxBasic The object or group being tested.
inScreenSpace bool Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."
camera FlxCamera Specify which game camera you want. If null getScreenXY() will just grab the first global camera. flx# - currently only one exists
return bool

overlapsAt() public method

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!
public overlapsAt ( float x, float y, FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = null ) : bool
x float The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
y float The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
objectOrGroup FlxBasic The object or group being tested.
inScreenSpace bool Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."
camera FlxCamera Specify which game camera you want. If null getScreenXY() will just grab the first global camera. flx# - currently only one exists
return bool

overlapsPoint() public method

Checks to see if a point in 2D world space overlaps this FlxObject object.
public overlapsPoint ( FlxPoint point, bool inScreenSpace = false, FlxCamera camera = null ) : bool
point FlxPoint The point in world space you want to check.
inScreenSpace bool Whether to take scroll factors into account when checking for overlap.
camera FlxCamera Specify which game camera you want. If null getScreenXY() will just grab the first global camera. flx# - currently only one exists
return bool

postUpdate() public method

Post-update is called right after update() on each object in the game loop. In FlxObject this function handles integrating the objects motion based on the velocity and acceleration settings, and tracking/clearing the touching flags.
public postUpdate ( ) : void
return void

preUpdate() public method

Pre-update is called right before update() on each object in the game loop. In FlxObject it controls the flicker timer, tracking the last coordinates for collision purposes, and checking if the object is moving along a path or not.
public preUpdate ( ) : void
return void

reset() public method

Handy function for reviving game objects. Resets their existence flags and position.
public reset ( float x, float y ) : void
x float The new X position of this object.
y float The new Y position of this object.
return void

separate() public static method

The main collision resolution function in flixel.
public static separate ( FlxObject objectOne, FlxObject objectTwo ) : bool
objectOne FlxObject Any FlxObject.
objectTwo FlxObject Any other FlxObject.
return bool

separateX() public static method

The X-axis component of the object separation process.
public static separateX ( FlxObject objectOne, FlxObject objectTwo ) : bool
objectOne FlxObject Any FlxObject.
objectTwo FlxObject Any other FlxObject.
return bool

separateY() public static method

The Y-axis component of the object separation process.
public static separateY ( FlxObject objectOne, FlxObject objectTwo ) : bool
objectOne FlxObject Any FlxObject.
objectTwo FlxObject Any other FlxObject.
return bool

stopFollowingPath() public method

Tells this object to stop following the path its on.
public stopFollowingPath ( bool destroyPath = false ) : void
destroyPath bool Tells this function whether to call destroy on the path object. Default value is false.
return void

update() public method

flx# - ? method not present in flixel
public update ( ) : void
return void

updateMotion() protected method

Internal function for updating the position and speed of this object. Useful for cases when you need to update this but are buried down in too many supers. Does a slightly fancier-than-normal integration to help with higher fidelity framerate-independenct motion.
protected updateMotion ( ) : void
return void

updatePathMotion() protected method

Internal function for moving the object along the path. Generally this function is called automatically by preUpdate(). The first half of the function decides if the object can advance to the next node in the path, while the second half handles actually picking a velocity toward the next node.
protected updatePathMotion ( ) : void
return void

Property Details

Acceleration public_oe property

How fast the speed of this object is changing. Useful for smooth movement and gravity
public FlxPoint,flxSharp.flxSharp Acceleration
return FlxPoint

Drag public_oe property

This is like deceleration that is only applied when acceleration is not affecting the sprite.
public FlxPoint,flxSharp.flxSharp Drag
return FlxPoint

MaxVelocity public_oe property

If you are using acceleration, you can use MaxVelocity with it to cap the speed automatically (very useful!).
public FlxPoint,flxSharp.flxSharp MaxVelocity
return FlxPoint

PZero protected_oe static_oe property

Should always represent (0,0) - useful for different things, for avoideing unnecessary new calls
protected static FlxPoint,flxSharp.flxSharp PZero
return FlxPoint

ScrollFactor public_oe property

A point that can store numbers from 0 to 1 (for X and Y independently) that governs how much this object is affected by the camera subsystem. 0 means it never moves, like a HUD element or far background graphic. 1 means it scrolls along a the same speed as the foreground layer. scrollFactor is initialized as (1,1) by default. flx# - CURRENTLY NOT IMPLEMENTED
public FlxPoint,flxSharp.flxSharp ScrollFactor
return FlxPoint

Velocity public_oe property

Basic speed of this object.
public FlxPoint,flxSharp.flxSharp Velocity
return FlxPoint

_flicker protected_oe property

Internal helper for Retro-styled flickering.
protected bool _flicker
return bool

_flickerTimer protected_oe property

Internal helper for Retro-styled flickering.
protected float _flickerTimer
return float

_pathInc protected_oe property

Internal helper for node navigation, specifically yo-yo and backwards movement.
protected int _pathInc
return int

_pathMode protected_oe property

Internal tracker for path behavior flags (like looping, horizontal only, etc).
protected uint _pathMode
return uint

_pathNodeIndex protected_oe property

Internal helper, tracks which node of the path this object is moving toward.
protected int _pathNodeIndex
return int

_pathRotate protected_oe property

Internal flag for whether the object's angle should be adjusted to the path angle during path follow behavior.
protected bool _pathRotate
return bool

_tagPoint protected_oe property

This is just a pre-allocated x-y point container to be used however you like.
protected FlxPoint,flxSharp.flxSharp _tagPoint
return FlxPoint

_tagRect protected_oe property

This is just a pre-allocated rectangle container to be used however you like.
protected FlxRect _tagRect
return FlxRect