Packageorg.flixel
Classpublic class FlxGame
InheritanceFlxGame Inheritance flash.display.Sprite

FlxGame is the heart of all flixel games, and contains a bunch of basic game loops and things. 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.



Public Properties
 PropertyDefined By
  _debugger : FlxDebugger
The debugger overlay object.
FlxGame
  _debuggerUp : Boolean
A handy boolean that keeps track of whether the debugger exists and is currently visible.
FlxGame
  _flashFramerate : uint
Framerate of the Flash player (NOT the game loop).
FlxGame
  forceDebugger : Boolean
Initialize and allow the flixel debugger overlay even in release mode.
FlxGame
  _maxAccumulation : uint
Max allowable accumulation (see _accumulator).
FlxGame
  _mouse : Sprite
Mouse cursor.
FlxGame
  _recording : Boolean
Flag for whether a new recording is being made.
FlxGame
  _recordingRequested : Boolean
Flag for whether a new recording was requested.
FlxGame
  _replay : FlxReplay
Container for a game replay object.
FlxGame
  _replayCallback : Function
This function, if set, is triggered when the callback stops playing.
FlxGame
  _replayCancelKeys : Array
Array that keeps track of keypresses that can cancel a replay.
FlxGame
  _replaying : Boolean
Flag for whether a replay is currently playing.
FlxGame
  _replayRequested : Boolean
Flag for whether a playback of a recording was requested.
FlxGame
  _replayTimer : int
Helps time out a replay if necessary.
FlxGame
  _requestedReset : Boolean
A flag for keeping track of whether a game reset was requested or not.
FlxGame
  _requestedState : FlxState
If a state change was requested, the new state object is stored here until we switch to it.
FlxGame
  _state : FlxState
Current game state.
FlxGame
  _step : uint
Milliseconds of time per step of the game loop.
FlxGame
  useSoundHotKeys : Boolean
Sets 0, -, and + to control the global volume sound volume.
FlxGame
  useSystemCursor : Boolean
Tells flixel to use the default system mouse cursor instead of custom Flixel mouse cursors.
FlxGame
Protected Properties
 PropertyDefined By
  _accumulator : int
Total number of milliseconds elapsed since last update loop.
FlxGame
  _created : Boolean
Whether the game object's basic initialization has finished yet.
FlxGame
  _focus : Sprite
The "focus lost" screen (see createFocusScreen()).
FlxGame
  ImgLogo : Class
FlxGame
  _iState : Class
Class type of the initial/first game state for the game, usually MenuState or something like that.
FlxGame
  junk : String
FlxGame
  _lostFocus : Boolean
Whether the Flash player lost focus.
FlxGame
  SndBeep : Class
FlxGame
  _soundTray : Sprite
The sound tray display container (see createSoundTray()).
FlxGame
  _soundTrayBars : Array
Helps display the volume bars on the sound tray.
FlxGame
  _soundTrayTimer : Number
Helps us auto-hide the sound tray after a volume change.
FlxGame
  _total : uint
Total number of milliseconds elapsed since game start.
FlxGame
Public Methods
 MethodDefined By
  
FlxGame(GameSizeX:uint, GameSizeY:uint, InitialState:Class, Zoom:Number = 1, GameFramerate:uint = 60, FlashFramerate:uint = 30, UseSystemCursor:Boolean = false)
Instantiate a new game object.
FlxGame
  
showSoundTray(Silent:Boolean = false):void
Makes the little volume tray slide out.
FlxGame
Protected Methods
 MethodDefined By
  
create(FlashEvent:Event):void
Used to instantiate the guts of the flixel game object once we have a valid reference to the root.
FlxGame
  
Sets up the darkened overlay with the big white "play" button that appears when a flixel game loses focus.
FlxGame
  
Sets up the "sound tray", the little volume meter that pops down sometimes.
FlxGame
  
draw():void
Goes through the game state and draws all the game objects and special effects.
FlxGame
  
onEnterFrame(FlashEvent:Event = null):void
Handles the onEnterFrame call and figures out how many updates and draw calls to do.
FlxGame
  
onFocus(FlashEvent:Event = null):void
Internal event handler for input and focus.
FlxGame
  
onFocusLost(FlashEvent:Event = null):void
Internal event handler for input and focus.
FlxGame
  
onKeyDown(FlashEvent:KeyboardEvent):void
Internal event handler for input and focus.
FlxGame
  
onKeyUp(FlashEvent:KeyboardEvent):void
Internal event handler for input and focus.
FlxGame
  
onMouseDown(FlashEvent:MouseEvent):void
Internal event handler for input and focus.
FlxGame
  
onMouseUp(FlashEvent:MouseEvent):void
Internal event handler for input and focus.
FlxGame
  
onMouseWheel(FlashEvent:MouseEvent):void
Internal event handler for input and focus.
FlxGame
  
step():void
This is the main game update logic section.
FlxGame
  
If there is a state change requested during the update loop, this function handles actual destroying the old state and related processes, and calls creates on the new state and plugs it into the game object.
FlxGame
  
update():void
This function is called by step() and updates the actual game state.
FlxGame
  
updateSoundTray(MS:Number):void
This function just updates the soundtray object.
FlxGame
Property Detail
_accumulatorproperty
protected var _accumulator:int

Total number of milliseconds elapsed since last update loop. Counts down as we step through the game loop.

_createdproperty 
protected var _created:Boolean

Whether the game object's basic initialization has finished yet.

_debuggerproperty 
public var _debugger:FlxDebugger

The debugger overlay object.

_debuggerUpproperty 
public var _debuggerUp:Boolean

A handy boolean that keeps track of whether the debugger exists and is currently visible.

_flashFramerateproperty 
public var _flashFramerate:uint

Framerate of the Flash player (NOT the game loop). Default = 30.

_focusproperty 
protected var _focus:Sprite

The "focus lost" screen (see createFocusScreen()).

_iStateproperty 
protected var _iState:Class

Class type of the initial/first game state for the game, usually MenuState or something like that.

_lostFocusproperty 
protected var _lostFocus:Boolean

Whether the Flash player lost focus.

_maxAccumulationproperty 
public var _maxAccumulation:uint

Max allowable accumulation (see _accumulator). Should always (and automatically) be set to roughly 2x the flash player framerate.

_mouseproperty 
public var _mouse:Sprite

Mouse cursor.

_recordingproperty 
public var _recording:Boolean

Flag for whether a new recording is being made.

_recordingRequestedproperty 
public var _recordingRequested:Boolean

Flag for whether a new recording was requested.

_replayproperty 
public var _replay:FlxReplay

Container for a game replay object.

_replayCallbackproperty 
public var _replayCallback:Function

This function, if set, is triggered when the callback stops playing.

_replayCancelKeysproperty 
public var _replayCancelKeys:Array

Array that keeps track of keypresses that can cancel a replay. Handy for skipping cutscenes or getting out of attract modes!

_replayingproperty 
public var _replaying:Boolean

Flag for whether a replay is currently playing.

_replayRequestedproperty 
public var _replayRequested:Boolean

Flag for whether a playback of a recording was requested.

_replayTimerproperty 
public var _replayTimer:int

Helps time out a replay if necessary.

_requestedResetproperty 
public var _requestedReset:Boolean

A flag for keeping track of whether a game reset was requested or not.

_requestedStateproperty 
public var _requestedState:FlxState

If a state change was requested, the new state object is stored here until we switch to it.

_soundTrayproperty 
protected var _soundTray:Sprite

The sound tray display container (see createSoundTray()).

_soundTrayBarsproperty 
protected var _soundTrayBars:Array

Helps display the volume bars on the sound tray.

_soundTrayTimerproperty 
protected var _soundTrayTimer:Number

Helps us auto-hide the sound tray after a volume change.

_stateproperty 
public var _state:FlxState

Current game state.

_stepproperty 
public var _step:uint

Milliseconds of time per step of the game loop. FlashEvent.g. 60 fps = 16ms.

_totalproperty 
protected var _total:uint

Total number of milliseconds elapsed since game start.

forceDebuggerproperty 
public var forceDebugger:Boolean

Initialize and allow the flixel debugger overlay even in release mode. Also useful if you don't use FlxPreloader!

The default value is false.

ImgLogoproperty 
protected var ImgLogo:Class

junkproperty 
protected var junk:String

SndBeepproperty 
protected var SndBeep:Class

useSoundHotKeysproperty 
public var useSoundHotKeys:Boolean

Sets 0, -, and + to control the global volume sound volume.

The default value is true.

useSystemCursorproperty 
public var useSystemCursor:Boolean

Tells flixel to use the default system mouse cursor instead of custom Flixel mouse cursors.

The default value is false.

Constructor Detail
FlxGame()Constructor
public function FlxGame(GameSizeX:uint, GameSizeY:uint, InitialState:Class, Zoom:Number = 1, GameFramerate:uint = 60, FlashFramerate:uint = 30, UseSystemCursor:Boolean = false)

Instantiate a new game object.

Parameters
GameSizeX:uint — The width of your game in game pixels, not necessarily final display pixels (see Zoom).
 
GameSizeY:uint — The height of your game in game pixels, not necessarily final display pixels (see Zoom).
 
InitialState:Class — The class name of the state you want to create and switch to first (e.g. MenuState).
 
Zoom:Number (default = 1) — The default level of zoom for the game's cameras (e.g. 2 = all pixels are now drawn at 2x). Default = 1.
 
GameFramerate:uint (default = 60) — How frequently the game should update (default is 60 times per second).
 
FlashFramerate:uint (default = 30) — Sets the actual display framerate for Flash player (default is 30 times per second).
 
UseSystemCursor:Boolean (default = false) — Whether to use the default OS mouse pointer, or to use custom flixel ones.
Method Detail
create()method
protected function create(FlashEvent:Event):void

Used to instantiate the guts of the flixel game object once we have a valid reference to the root.

Parameters

FlashEvent:Event — Just a Flash system event, not too important for our purposes.

createFocusScreen()method 
protected function createFocusScreen():void

Sets up the darkened overlay with the big white "play" button that appears when a flixel game loses focus.

createSoundTray()method 
protected function createSoundTray():void

Sets up the "sound tray", the little volume meter that pops down sometimes.

draw()method 
protected function draw():void

Goes through the game state and draws all the game objects and special effects.

onEnterFrame()method 
protected function onEnterFrame(FlashEvent:Event = null):void

Handles the onEnterFrame call and figures out how many updates and draw calls to do.

Parameters

FlashEvent:Event (default = null) — Flash event.

onFocus()method 
protected function onFocus(FlashEvent:Event = null):void

Internal event handler for input and focus.

Parameters

FlashEvent:Event (default = null) — Flash event.

onFocusLost()method 
protected function onFocusLost(FlashEvent:Event = null):void

Internal event handler for input and focus.

Parameters

FlashEvent:Event (default = null) — Flash event.

onKeyDown()method 
protected function onKeyDown(FlashEvent:KeyboardEvent):void

Internal event handler for input and focus.

Parameters

FlashEvent:KeyboardEvent — Flash keyboard event.

onKeyUp()method 
protected function onKeyUp(FlashEvent:KeyboardEvent):void

Internal event handler for input and focus.

Parameters

FlashEvent:KeyboardEvent — Flash keyboard event.

onMouseDown()method 
protected function onMouseDown(FlashEvent:MouseEvent):void

Internal event handler for input and focus.

Parameters

FlashEvent:MouseEvent — Flash mouse event.

onMouseUp()method 
protected function onMouseUp(FlashEvent:MouseEvent):void

Internal event handler for input and focus.

Parameters

FlashEvent:MouseEvent — Flash mouse event.

onMouseWheel()method 
protected function onMouseWheel(FlashEvent:MouseEvent):void

Internal event handler for input and focus.

Parameters

FlashEvent:MouseEvent — Flash mouse event.

showSoundTray()method 
public function showSoundTray(Silent:Boolean = false):void

Makes the little volume tray slide out.

Parameters

Silent:Boolean (default = false) — Whether or not it should beep.

step()method 
protected function step():void

This is the main game update logic section. The onEnterFrame() handler is in charge of calling this the appropriate number of times each frame. This block handles state changes, replays, all that good stuff.

switchState()method 
protected function switchState():void

If there is a state change requested during the update loop, this function handles actual destroying the old state and related processes, and calls creates on the new state and plugs it into the game object.

update()method 
protected function update():void

This function is called by step() and updates the actual game state. May be called multiple times per "frame" or draw call.

updateSoundTray()method 
protected function updateSoundTray(MS:Number):void

This function just updates the soundtray object.

Parameters

MS:Number