class flixel.FlxG

Available on all platforms

Global helper class for audio, input, the camera system, the debugger and other global properties.

Class Fields

static var VERSION:FlxVersion

The HaxeFlixel version, in semantic versioning syntax. Use Std.string() * on it to get a String formatted like this: "HaxeFlixel MAJOR.MINOR.PATCH-PATCH_VERSION".

static var autoPause:Bool

Whether the game should be paused when focus is lost or not. Use FLXNOFOCUSLOSTSCREEN if you only want to get rid of the default * pause screen. Override onFocus() and onFocusLost() for your own behaviour in your state.

static var bitmap:BitmapFrontEnd

Contains things related to bimtaps, for example regarding the bitmap cache and the cache itself.

static var camera:FlxCamera

By default this just refers to the first entry in the FlxG.cameras.list * array but you can do what you like with it.

static var cameras:CameraFrontEnd

Contains things related to cameras, a list of all cameras and several effects like flash() or fade().

static var console:ConsoleFrontEnd

Used to register functions and objects or add new commands to the console window.

static var debugger:DebuggerFrontEnd

Used it to show / hide the debguger, change its layout, * activate debug drawing or change the key used to toggle it.

static var drawFramerate:Int

How many times you want your game to step each second. More steps usually means greater responsiveness, * but it can also slowdown your game if the stage can't keep up with the update routine. NOTE: This is NOT the same thing as the Update framerate!

static var elapsed:Float

Represents the amount of time in seconds that passed since last frame.

static var fixedTimestep:Bool

WARNING: Changing this can lead to issues with physics and the recording system. Setting this to * false might lead to smoother animations (even at lower fps) at the cost of physics accuracy.

static var fullscreen:Bool

Use this to toggle between fullscreen and normal mode. Works in cpp and flash. * You can easily toggle fullscreen with eg: FlxG.fullscreen = !FlxG.fullscreen;

static var game:FlxGame

Internal tracker for game object.

static var gamepads:FlxGamepadManager

A reference to a FlxGamepadManager object.

static var height:Int

The height of the screen in game pixels. Read-only, use resizeGame() to change.

static var inputs:InputFrontEnd

Mostly used internally, but you can use it too to reset inputs and create input classes of your own.

static var keys:FlxKeyboard

Used for keyboard input e.g.: check if the left arrow key is * pressed with if (FlxG.keys.pressed.LEFT) { } in update().

static var log:LogFrontEnd

Used to add messages to the log window or enable trace() redirection.

static var maxElapsed:Float

Useful when the timestep is NOT fixed (i.e. variable), to prevent jerky movement or erratic behavior at very low fps. * Essentially locks the framerate to a minimum value - any slower and you'll get slowdown instead of frameskip; default is 1/10th of a second.

static var mouse:FlxMouse

Used for mouse input. e.g.: check if the left mouse button * is pressed with if (FlxG.mouse.pressed) { }) in update().

static var plugins:PluginFrontEnd

Contains a list of all plugins and the functions required to add(), remove() them etc.

static var save:FlxSave

A FlxSave used internally by flixel to save sound preferences and * the history of the console window, but no reason you can't use it for your own stuff too!

static var scaleMode:BaseScaleMode

The scale mode the game should use - available policies are FillScaleMode, FixedScaleMode, * RatioScaleMode, RelativeScaleMode and StageSizeScaleMode.

static var signals:SignalFrontEnd

Contains system-wide signals like gameResize or stateSwitch.

static var sound:SoundFrontEnd

Contains a list of all sounds and other things to manage or play() sounds.

static var stage:Stage

Read-only: retrieves the Flash stage object (required for event listeners) * Will be null if it's not safe/useful yet.

static var state:FlxState

Read-only: access the current game state from anywhere. Consider using addChildBelowMouse() * if you want to add a DisplayObject to the stage instead of directly adding it here!

static var swipes:Array<FlxSwipe>

Contains all "swipes" from both mouse and touch input that have just ended.

static var timeScale:Float

How fast or slow time should pass in the game; default is 1.0.

static var touches:FlxTouchManager

Useful for devices with multitouch support.

static var updateFramerate:Int

How many times you want your game to update each second. More updates usually means better collisions and smoother motion. * NOTE: This is NOT the same thing as the draw framerate!

static var vcr:VCRFrontEnd

Contains all the functions needed for recording and replaying.

static var watch:WatchFrontEnd

Used to add or remove things to / from the watch window.

static var width:Int

The width of the screen in game pixels. Read-only, use resizeGame() to change.

static var worldBounds:FlxRect

The dimensions of the game world, used by the quad tree for collisions and overlap checks. * Use .set() instead of creating a new object!

static var worldDivisions:Int

How many times the quad tree should divide the world on each axis. Generally, sparse collisions can have fewer divisons, * while denser collision activity usually profits from more. Default value is 6.

static function addChildBelowMouse<T>(Child:T, ?IndexModifier:Int = 0):T

Regular DisplayObjects are normally displayed over the flixel cursor and the flixel debugger if simply * added to stage. This function simplifies things by adding a DisplayObject directly below mouse level. * *

Child

The DisplayObject to add *

IndexModifier

Amount to add to the index - makes sure the index stays within bounds! *

returns

The added DisplayObject

static function collide(?ObjectOrGroup1:FlxBasic = null, ?ObjectOrGroup2:FlxBasic = null, ?NotifyCallback:Dynamic ->Dynamic ->Void = null):Bool

Call this function to see if one FlxObject collides with another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! For maximum performance try bundling a lot of objects * together using a FlxGroup (or even bundling groups together!). * This function just calls FlxG.overlap and presets the ProcessCallback parameter to FlxObject.separate. * To create your own collision logic, write your own ProcessCallback and use FlxG.overlap to set it up. * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space. * *

ObjectOrGroup1

The first object or group you want to check. *

ObjectOrGroup2

The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. *

NotifyCallback

A function with two FlxObject parameters - e.g. myOverlapFunction(Object1:FlxObject,Object2:FlxObject) - that is called if those two objects overlap. *

returns

Whether any objects were successfully collided/separated.

static function openURL(URL:String, ?Target:String = '_blank'):Void

Opens a web page, by default a new tab or window. If the URL does not * already start with "http://" or "https://", it gets added automatically. * *

URL

The address of the web page. *

Target

"blank", "self", "parent" or "top"

static function overlap(?ObjectOrGroup1:FlxBasic = null, ?ObjectOrGroup2:FlxBasic = null, ?NotifyCallback:Dynamic ->Dynamic ->Void = null, ?ProcessCallback:Dynamic ->Dynamic ->Bool = null):Bool

Call this function to see if one FlxObject overlaps another. * Can be called with one object and one group, or two groups, or two objects, * whatever floats your boat! For maximum performance try bundling a lot of objects * together using a FlxGroup (or even bundling groups together!). * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space. * *

ObjectOrGroup1

The first object or group you want to check. *

ObjectOrGroup2

The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group. *

NotifyCallback

A function with two FlxObject parameters - e.g. myOverlapFunction(Object1:FlxObject,Object2:FlxObject) - that is called if those two objects overlap. *

ProcessCallback

A function with two FlxObject parameters - e.g. myOverlapFunction(Object1:FlxObject,Object2:FlxObject) - that is called if those two objects overlap. If a ProcessCallback is provided, then NotifyCallback will only be called if ProcessCallback returns true for those objects! *

returns

Whether any overlaps were detected.

static function pixelPerfectOverlap(Sprite1:FlxSprite, Sprite2:FlxSprite, ?AlphaTolerance:Int = 255, ?Camera:FlxCamera = null):Bool

A Pixel Perfect Collision check between two FlxSprites. It will do a bounds check first, and if that passes it will run a * pixel perfect match on the intersecting area. Works with rotated and animated sprites. May be slow, so use it sparingly. * *

Sprite1

The first FlxSprite to test against *

Sprite2

The second FlxSprite to test again, sprite order is irrelevant *

AlphaTolerance

The tolerance value above which alpha pixels are included. Default to 255 (must be fully opaque for collision). *

Camera

If the collision is taking place in a camera other than FlxG.camera (the default/current) then pass it here *

returns

Whether the sprites collide

static function removeChild<T>(Child:T):T

Removes a child from the flixel display list, if it is part of it. * *

Child

The DisplayObject to add *

returns

The removed DisplayObject

static function resetGame():Void

Like hitting the reset button a game console, this will re-launch the game as if it just started.

static function resetState():Void

Request a reset of the current game state.

static function resizeGame(Width:Int, Height:Int):Void

Handy helper functions that takes care of all the things to resize the game.

static function switchState(State:FlxState):Void

Switch from the current game state to the one specified here.