
org.flixel.FlxBasic Maven / Gradle / Ivy
The newest version!
package org.flixel;
import com.badlogic.gdx.utils.Array;
/**
* This is a useful "generic" Flixel object.
* Both FlxObject
and FlxGroup
extend this class,
* as do the plugins. Has no size, position or graphical data.
*
* @author Ka Wing Chin
*/
public class FlxBasic
{
static int _ACTIVECOUNT;
static int _VISIBLECOUNT;
/**
* IDs seem like they could be pretty useful, huh?
* They're not actually used for anything yet though.
*/
public int ID;
/**
* Controls whether update()
and draw()
are automatically called by FlxState/FlxGroup.
*/
public boolean exists;
/**
* Controls whether update()
is automatically called by FlxState/FlxGroup.
*/
public boolean active;
/**
* Controls whether draw()
is automatically called by FlxState/FlxGroup.
*/
public boolean visible;
/**
* Useful state for many game objects - "dead" (!alive) vs alive.
* kill()
and revive()
both flip this switch (along with exists, but you can override that).
*/
public boolean alive;
/**
* An array of camera objects that this object will use during draw()
.
* This value will initialize itself during the first draw to automatically
* point at the main camera list out in FlxG
unless you already set it.
* You can also change it afterward too, very flexible!
*/
public Array cameras;
/**
* Setting this to true will prevent the object from appearing
* when the visual debug mode in the debugger overlay is toggled on.
*/
public boolean ignoreDrawDebug;
/**
* Instantiate the basic flixel object.
*/
public FlxBasic()
{
ID = -1;
exists = true;
active = true;
visible = true;
alive = true;
ignoreDrawDebug = false;
}
/**
* Override this function to null out variables or manually call
* destroy()
on class members if necessary.
* Don't forget to call super.destroy()
!
*/
public void destroy() {}
/**
* Pre-update is called right before update()
on each object in the game loop.
*/
public void preUpdate()
{
_ACTIVECOUNT++;
}
/**
* Override this function to update your class's position and appearance.
* This is where most of your game rules and behavioral code will go.
*/
public void update()
{
}
/**
* Post-update is called right after update()
on each object in the game loop.
*/
public void postUpdate()
{
}
/**
* Override this function to control how the object is drawn.
* Overriding draw()
is rarely necessary, but can be very useful.
*/
public void draw()
{
if(cameras == null)
cameras = FlxG.cameras;
FlxCamera camera = FlxG._activeCamera;
if(!cameras.contains(camera,true))
return;
_VISIBLECOUNT++;
if(FlxG.visualDebug && !ignoreDrawDebug)
drawDebug(camera);
}
/**
* Override this function to draw custom "debug mode" graphics to the
* specified camera while the debugger's visual mode is toggled on.
*
* @param Camera Which camera to draw the debug visuals to.
*/
public void drawDebug(FlxCamera Camera)
{
}
/**
* Override this function to draw custom "debug mode" graphics to the
* specified camera while the debugger's visual mode is toggled on.
*/
public void drawDebug()
{
drawDebug(null);
}
/**
* Handy function for "killing" game objects.
* Default behavior is to flag them as nonexistent AND dead.
* However, if you want the "corpse" to remain in the game,
* like to animate an effect or whatever, you should override this,
* setting only alive to false, and leaving exists true.
*/
public void kill()
{
alive = false;
exists = false;
}
/**
* Handy function for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this function is most often called by FlxObject.reset()
.
*/
public void revive()
{
alive = true;
exists = true;
}
/**
* Convert object to readable string name. Useful for debugging, save games, etc.
*/
public String toString()
{
return FlxU.getClassName(this,true);
}
/**
* Whether the sprite is being rendered in simple mode or not.
*/
public boolean isSimpleRender()
{
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy