Skip to content

Flixel Structure

WingEraser edited this page Feb 15, 2014 · 3 revisions

The goal of this guide is to walk you through the process how flixel works. We look at the structure of flixel.

##FlxGame This is the start point when you create a new game. It’s the heart of flixel, it tracks, update and draw your game objects. It is a long and sloppy file that you shouldn't have to worry about too much! It is basically only used to create your game object in the first place, after that FlxG and FlxState have all the useful stuff you actually need.

##FlxState One of the arguments that are required in the constructor of FlxGame is an FlxState class. Flixel helps you keep things organized with this FlxState. Its uses the state pattern which means that the different parts of your game that has other behaviours can be written in different states. All your game logic will be done as part of a "state" and not in FlxGame. To add an object to this class, simply call add(object).

##Game objects, FlxBasic, FlxObject, FlxSprite FlxBasic is the generic class. The classes FlxObject and FlxGroup extend this class, as do the plugins.

FlxObject is the bas class for most of the display objects. It includes some basic attributes about game objects, including retro-style flickering, basic state information, sizes, scrolling, and basic physics and motion.

FlxSprite is a graphical representation of a game object. It comes with a bunch of graphics options and abilities, like animation and stamping. You’ll probably inherit this class the most if you want to render your game object on screen.

##Group FlxGroup is an organizational class that can update and render a bunch of FlxBasic. It includes handy utilities for accessing game object that are part of that group. Read "Memory Management" about those utilities.

FlxBasic subclasses

##Loop Flixel uses a Deterministic Delta Timer to handle steps within the engine. The step is processed in the main loop (FlxGame.step()). During the loop FlxState.draw() and FlxState.update() will be called to render all the game objects special effects and update the physics. The first that got added to the state will be draw and updated as first. In FlxState.update() you will write the behavior of the state.

@Override
public void update()
{
	// Animation and movement code usually goes up here

	super.update();

	// Usually the only things that you do after updating
	// is stuff like updating extra hitboxes or attached
	// animations or particles.
}

Loop

##FlxG and FlxU FlxG is a Global helper class. It contains useful functions for audio, input, basic info and the camera system among the other things. FlxU is a Utility class for maths and colors. You’ll use them a lot during your game development.