Packageorg.flixel
Classpublic class FlxCamera
InheritanceFlxCamera Inheritance FlxBasic Inheritance Object

The camera class is used to display the game's visuals in the Flash player. By default one camera is created automatically, that is the same size as the Flash player. You can add more cameras or even replace the main camera using utilities in FlxG.



Public Properties
 PropertyDefined By
 Inheritedactive : Boolean
Controls whether update() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_ACTIVECOUNT : uint
[static]
FlxBasic
 Inheritedalive : Boolean
Useful state for many game objects - "dead" (!alive) vs alive.
FlxBasic
  alpha : Number
The alpha value of this camera display (a Number between 0.0 and 1.0).
FlxCamera
  angle : Number
The angle of the camera display (in degrees).
FlxCamera
  antialiasing : Boolean
Whether the camera display is smooth and filtered, or chunky and pixelated.
FlxCamera
  bgColor : uint
The natural background color of the camera.
FlxCamera
  bounds : FlxRect
The edges of the camera's range, i.e.
FlxCamera
  buffer : BitmapData
The actual bitmap data of the camera display itself.
FlxCamera
 Inheritedcameras : Array
An array of camera objects that this object will use during draw().
FlxBasic
  color : uint
The color tint of the camera display.
FlxCamera
  deadzone : FlxRect
You can assign a "dead zone" to the camera in order to better control its movement.
FlxCamera
  defaultZoom : Number
[static] While you can alter the zoom of each camera after the fact, this variable determines what value the camera will start at when created.
FlxCamera
 Inheritedexists : Boolean
Controls whether update() and draw() are automatically called by FlxState/FlxGroup.
FlxBasic
  _flashOffsetX : Number
Internal, used to render buffer to screen space.
FlxCamera
  _flashOffsetY : Number
Internal, used to render buffer to screen space.
FlxCamera
  _flashSprite : Sprite
Internal, used to render buffer to screen space.
FlxCamera
  height : uint
How tall the camera display is, in game pixels.
FlxCamera
 InheritedID : int
IDs seem like they could be pretty useful, huh? They're not actually used for anything yet though.
FlxBasic
 InheritedignoreDrawDebug : Boolean
Setting this to true will prevent the object from appearing when the visual debug mode in the debugger overlay is toggled on.
FlxBasic
  screen : FlxSprite
Sometimes it's easier to just work with a FlxSprite than it is to work directly with the BitmapData buffer.
FlxCamera
  scroll : FlxPoint
Stores the basic parallax scrolling values.
FlxCamera
  target : FlxObject
Tells the camera to follow this FlxObject object around.
FlxCamera
 Inheritedvisible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_VISIBLECOUNT : uint
[static]
FlxBasic
  width : uint
How wide the camera display is, in game pixels.
FlxCamera
  x : Number
The X position of this camera's display.
FlxCamera
  y : Number
The Y position of this camera's display.
FlxCamera
  zoom : Number
The zoom level of this camera.
FlxCamera
Protected Properties
 PropertyDefined By
  _color : uint
Internal, help with color transforming the flash bitmap.
FlxCamera
  _fill : BitmapData
Internal helper variable for doing better wipes/fills between renders.
FlxCamera
  _flashBitmap : Bitmap
Internal, used to render buffer to screen space.
FlxCamera
  _flashPoint : Point
Internal, used to render buffer to screen space.
FlxCamera
  _flashRect : Rectangle
Internal, used to render buffer to screen space.
FlxCamera
  _fxFadeAlpha : Number
Internal, used to control the "fade" special effect.
FlxCamera
  _fxFadeColor : uint
Internal, used to control the "fade" special effect.
FlxCamera
  _fxFadeComplete : Function
Internal, used to control the "fade" special effect.
FlxCamera
  _fxFadeDuration : Number
Internal, used to control the "fade" special effect.
FlxCamera
  _fxFlashAlpha : Number
Internal, used to control the "flash" special effect.
FlxCamera
  _fxFlashColor : uint
Internal, used to control the "flash" special effect.
FlxCamera
  _fxFlashComplete : Function
Internal, used to control the "flash" special effect.
FlxCamera
  _fxFlashDuration : Number
Internal, used to control the "flash" special effect.
FlxCamera
  _fxShakeComplete : Function
Internal, used to control the "shake" special effect.
FlxCamera
  _fxShakeDirection : uint
Internal, used to control the "shake" special effect.
FlxCamera
  _fxShakeDuration : Number
Internal, used to control the "shake" special effect.
FlxCamera
  _fxShakeIntensity : Number
Internal, used to control the "shake" special effect.
FlxCamera
  _fxShakeOffset : FlxPoint
Internal, used to control the "shake" special effect.
FlxCamera
  _point : FlxPoint
Internal, to help avoid costly allocations.
FlxCamera
  _zoom : Number
Indicates how far the camera is zoomed in.
FlxCamera
Public Methods
 MethodDefined By
  
FlxCamera(X:int, Y:int, Width:int, Height:int, Zoom:Number = 0)
Instantiates a new camera at the specified location, with the specified size and zoom level.
FlxCamera
  
Copy the bounds, focus object, and deadzone info from an existing camera.
FlxCamera
  
destroy():void
[override] Clean up memory.
FlxCamera
 Inherited
draw():void
Override this function to control how the object is drawn.
FlxBasic
 Inherited
drawDebug(Camera:FlxCamera = null):void
Override this function to draw custom "debug mode" graphics to the specified camera while the debugger's visual mode is toggled on.
FlxBasic
  
drawFX():void
Internal helper function, handles the actual drawing of all the special effects.
FlxCamera
  
fade(Color:uint = 0xff000000, Duration:Number = 1, OnComplete:Function = null, Force:Boolean = false):void
The screen is gradually filled with this color.
FlxCamera
  
fill(Color:uint = 0, BlendAlpha:Boolean = true):void
Fill the camera with the specified color.
FlxCamera
  
flash(Color:uint = 0xffffffff, Duration:Number = 1, OnComplete:Function = null, Force:Boolean = false):void
The screen is filled with this color and gradually returns to normal.
FlxCamera
  
focusOn(Point:FlxPoint):void
Move the camera focus to this location instantly.
FlxCamera
  
follow(Target:FlxObject, Style:uint):void
Tells this camera object what FlxObject to track.
FlxCamera
  
Fetches a reference to the Flash Sprite object that contains the camera display in the Flash display list.
FlxCamera
  
The scale of the camera object, irrespective of zoom.
FlxCamera
 Inherited
kill():void
Handy function for "killing" game objects.
FlxBasic
 Inherited
postUpdate():void
Post-update is called right after update() on each object in the game loop.
FlxBasic
 Inherited
preUpdate():void
Pre-update is called right before update() on each object in the game loop.
FlxBasic
 Inherited
revive():void
Handy function for bringing game objects "back to life".
FlxBasic
  
setBounds(X:Number = 0, Y:Number = 0, Width:Number = 0, Height:Number = 0, UpdateWorld:Boolean = false):void
Specify the boundaries of the level or where the camera is allowed to move.
FlxCamera
  
shake(Intensity:Number = 0.05, Duration:Number = 0.5, OnComplete:Function = null, Force:Boolean = true, Direction:uint):void
A simple screen-shake effect.
FlxCamera
  
stopFX():void
Just turns off all the camera effects instantly.
FlxCamera
 Inherited
toString():String
Convert object to readable string name.
FlxBasic
  
update():void
[override] Updates the camera scroll as well as special effects like screen-shake or fades.
FlxCamera
Public Constants
 ConstantDefined By
  SHAKE_BOTH_AXES : uint = 0
[static] Camera "shake" effect preset: shake camera on both the X and Y axes.
FlxCamera
  SHAKE_HORIZONTAL_ONLY : uint = 1
[static] Camera "shake" effect preset: shake camera on the X axis only.
FlxCamera
  SHAKE_VERTICAL_ONLY : uint = 2
[static] Camera "shake" effect preset: shake camera on the Y axis only.
FlxCamera
  STYLE_LOCKON : uint = 0
[static] Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
FlxCamera
  STYLE_PLATFORMER : uint = 1
[static] Camera "follow" style preset: camera deadzone is narrow but tall.
FlxCamera
  STYLE_TOPDOWN : uint = 2
[static] Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.
FlxCamera
  STYLE_TOPDOWN_TIGHT : uint = 3
[static] Camera "follow" style preset: camera deadzone is a small square around the focus object.
FlxCamera
Property Detail
_colorproperty
protected var _color:uint

Internal, help with color transforming the flash bitmap.

_fillproperty 
protected var _fill:BitmapData

Internal helper variable for doing better wipes/fills between renders.

_flashBitmapproperty 
protected var _flashBitmap:Bitmap

Internal, used to render buffer to screen space.

_flashOffsetXproperty 
public var _flashOffsetX:Number

Internal, used to render buffer to screen space.

_flashOffsetYproperty 
public var _flashOffsetY:Number

Internal, used to render buffer to screen space.

_flashPointproperty 
protected var _flashPoint:Point

Internal, used to render buffer to screen space.

_flashRectproperty 
protected var _flashRect:Rectangle

Internal, used to render buffer to screen space.

_flashSpriteproperty 
public var _flashSprite:Sprite

Internal, used to render buffer to screen space.

_fxFadeAlphaproperty 
protected var _fxFadeAlpha:Number

Internal, used to control the "fade" special effect.

_fxFadeColorproperty 
protected var _fxFadeColor:uint

Internal, used to control the "fade" special effect.

_fxFadeCompleteproperty 
protected var _fxFadeComplete:Function

Internal, used to control the "fade" special effect.

_fxFadeDurationproperty 
protected var _fxFadeDuration:Number

Internal, used to control the "fade" special effect.

_fxFlashAlphaproperty 
protected var _fxFlashAlpha:Number

Internal, used to control the "flash" special effect.

_fxFlashColorproperty 
protected var _fxFlashColor:uint

Internal, used to control the "flash" special effect.

_fxFlashCompleteproperty 
protected var _fxFlashComplete:Function

Internal, used to control the "flash" special effect.

_fxFlashDurationproperty 
protected var _fxFlashDuration:Number

Internal, used to control the "flash" special effect.

_fxShakeCompleteproperty 
protected var _fxShakeComplete:Function

Internal, used to control the "shake" special effect.

_fxShakeDirectionproperty 
protected var _fxShakeDirection:uint

Internal, used to control the "shake" special effect.

_fxShakeDurationproperty 
protected var _fxShakeDuration:Number

Internal, used to control the "shake" special effect.

_fxShakeIntensityproperty 
protected var _fxShakeIntensity:Number

Internal, used to control the "shake" special effect.

_fxShakeOffsetproperty 
protected var _fxShakeOffset:FlxPoint

Internal, used to control the "shake" special effect.

_pointproperty 
protected var _point:FlxPoint

Internal, to help avoid costly allocations.

_zoomproperty 
protected var _zoom:Number

Indicates how far the camera is zoomed in.

alphaproperty 
alpha:Number

The alpha value of this camera display (a Number between 0.0 and 1.0).


Implementation
    public function get alpha():Number
    public function set alpha(value:Number):void
angleproperty 
angle:Number

The angle of the camera display (in degrees). Currently yields weird display results, since cameras aren't nested in an extra display object yet.


Implementation
    public function get angle():Number
    public function set angle(value:Number):void
antialiasingproperty 
antialiasing:Boolean

Whether the camera display is smooth and filtered, or chunky and pixelated. Default behavior is chunky-style.


Implementation
    public function get antialiasing():Boolean
    public function set antialiasing(value:Boolean):void
bgColorproperty 
public var bgColor:uint

The natural background color of the camera. Defaults to FlxG.bgColor. NOTE: can be transparent for crazy FX!

boundsproperty 
public var bounds:FlxRect

The edges of the camera's range, i.e. where to stop scrolling. Measured in game pixels and world coordinates.

bufferproperty 
public var buffer:BitmapData

The actual bitmap data of the camera display itself.

colorproperty 
color:uint

The color tint of the camera display.


Implementation
    public function get color():uint
    public function set color(value:uint):void
deadzoneproperty 
public var deadzone:FlxRect

You can assign a "dead zone" to the camera in order to better control its movement. The camera will always keep the focus object inside the dead zone, unless it is bumping up against the bounds rectangle's edges. The deadzone's coordinates are measured from the camera's upper left corner in game pixels. For rapid prototyping, you can use the preset deadzones (e.g. STYLE_PLATFORMER) with follow().

defaultZoomproperty 
public static var defaultZoom:Number

While you can alter the zoom of each camera after the fact, this variable determines what value the camera will start at when created.

heightproperty 
public var height:uint

How tall the camera display is, in game pixels.

screenproperty 
public var screen:FlxSprite

Sometimes it's easier to just work with a FlxSprite than it is to work directly with the BitmapData buffer. This sprite reference will allow you to do exactly that.

scrollproperty 
public var scroll:FlxPoint

Stores the basic parallax scrolling values.

targetproperty 
public var target:FlxObject

Tells the camera to follow this FlxObject object around.

widthproperty 
public var width:uint

How wide the camera display is, in game pixels.

xproperty 
public var x:Number

The X position of this camera's display. Zoom does NOT affect this number. Measured in pixels from the left side of the flash window.

yproperty 
public var y:Number

The Y position of this camera's display. Zoom does NOT affect this number. Measured in pixels from the top of the flash window.

zoomproperty 
zoom:Number

The zoom level of this camera. 1 = 1:1, 2 = 2x zoom, etc.


Implementation
    public function get zoom():Number
    public function set zoom(value:Number):void
Constructor Detail
FlxCamera()Constructor
public function FlxCamera(X:int, Y:int, Width:int, Height:int, Zoom:Number = 0)

Instantiates a new camera at the specified location, with the specified size and zoom level.

Parameters
X:int — X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
 
Y:int — Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
 
Width:int — The width of the camera display in pixels.
 
Height:int — The height of the camera display in pixels.
 
Zoom:Number (default = 0) — The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.
Method Detail
copyFrom()method
public function copyFrom(Camera:FlxCamera):FlxCamera

Copy the bounds, focus object, and deadzone info from an existing camera.

Parameters

Camera:FlxCamera — The camera you want to copy from.

Returns
FlxCamera — A reference to this FlxCamera object.
destroy()method 
override public function destroy():void

Clean up memory.

drawFX()method 
public function drawFX():void

Internal helper function, handles the actual drawing of all the special effects.

fade()method 
public function fade(Color:uint = 0xff000000, Duration:Number = 1, OnComplete:Function = null, Force:Boolean = false):void

The screen is gradually filled with this color.

Parameters

Color:uint (default = 0xff000000) — The color you want to use.
 
Duration:Number (default = 1) — How long it takes for the fade to finish.
 
OnComplete:Function (default = null) — A function you want to run when the fade finishes.
 
Force:Boolean (default = false) — Force the effect to reset.

fill()method 
public function fill(Color:uint = 0, BlendAlpha:Boolean = true):void

Fill the camera with the specified color.

Parameters

Color:uint (default = 0) — The color to fill with in 0xAARRGGBB hex format.
 
BlendAlpha:Boolean (default = true) — Whether to blend the alpha value or just wipe the previous contents. Default is true.

flash()method 
public function flash(Color:uint = 0xffffffff, Duration:Number = 1, OnComplete:Function = null, Force:Boolean = false):void

The screen is filled with this color and gradually returns to normal.

Parameters

Color:uint (default = 0xffffffff) — The color you want to use.
 
Duration:Number (default = 1) — How long it takes for the flash to fade.
 
OnComplete:Function (default = null) — A function you want to run when the flash finishes.
 
Force:Boolean (default = false) — Force the effect to reset.

focusOn()method 
public function focusOn(Point:FlxPoint):void

Move the camera focus to this location instantly.

Parameters

Point:FlxPoint — Where you want the camera to focus.

follow()method 
public function follow(Target:FlxObject, Style:uint):void

Tells this camera object what FlxObject to track.

Parameters

Target:FlxObject — The object you want the camera to track. Set to null to not follow anything.
 
Style:uint (default = NaN) — Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().

getContainerSprite()method 
public function getContainerSprite():Sprite

Fetches a reference to the Flash Sprite object that contains the camera display in the Flash display list. Uses include 3D projection, advanced display list modification, and more. NOTE: We don't recommend modifying this directly unless you are fairly experienced. For simple changes to the camera display, like scaling, rotation, and color tinting, we recommend using the existing FlxCamera variables.

Returns
Sprite — A Flash Sprite object containing the camera display.
getScale()method 
public function getScale():FlxPoint

The scale of the camera object, irrespective of zoom. Currently yields weird display results, since cameras aren't nested in an extra display object yet.

Returns
FlxPoint
setBounds()method 
public function setBounds(X:Number = 0, Y:Number = 0, Width:Number = 0, Height:Number = 0, UpdateWorld:Boolean = false):void

Specify the boundaries of the level or where the camera is allowed to move.

Parameters

X:Number (default = 0) — The smallest X value of your level (usually 0).
 
Y:Number (default = 0) — The smallest Y value of your level (usually 0).
 
Width:Number (default = 0) — The largest X value of your level (usually the level width).
 
Height:Number (default = 0) — The largest Y value of your level (usually the level height).
 
UpdateWorld:Boolean (default = false) — Whether the global quad-tree's dimensions should be updated to match (default: false).

shake()method 
public function shake(Intensity:Number = 0.05, Duration:Number = 0.5, OnComplete:Function = null, Force:Boolean = true, Direction:uint):void

A simple screen-shake effect.

Parameters

Intensity:Number (default = 0.05) — Percentage of screen size representing the maximum distance that the screen can move while shaking.
 
Duration:Number (default = 0.5) — The length in seconds that the shaking effect should last.
 
OnComplete:Function (default = null) — A function you want to run when the shake effect finishes.
 
Force:Boolean (default = true) — Force the effect to reset (default = true, unlike flash() and fade()!).
 
Direction:uint (default = NaN) — Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).

stopFX()method 
public function stopFX():void

Just turns off all the camera effects instantly.

update()method 
override public function update():void

Updates the camera scroll as well as special effects like screen-shake or fades.

Constant Detail
SHAKE_BOTH_AXESConstant
public static const SHAKE_BOTH_AXES:uint = 0

Camera "shake" effect preset: shake camera on both the X and Y axes.

SHAKE_HORIZONTAL_ONLYConstant 
public static const SHAKE_HORIZONTAL_ONLY:uint = 1

Camera "shake" effect preset: shake camera on the X axis only.

SHAKE_VERTICAL_ONLYConstant 
public static const SHAKE_VERTICAL_ONLY:uint = 2

Camera "shake" effect preset: shake camera on the Y axis only.

STYLE_LOCKONConstant 
public static const STYLE_LOCKON:uint = 0

Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.

STYLE_PLATFORMERConstant 
public static const STYLE_PLATFORMER:uint = 1

Camera "follow" style preset: camera deadzone is narrow but tall.

STYLE_TOPDOWNConstant 
public static const STYLE_TOPDOWN:uint = 2

Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.

STYLE_TOPDOWN_TIGHTConstant 
public static const STYLE_TOPDOWN_TIGHT:uint = 3

Camera "follow" style preset: camera deadzone is a small square around the focus object.