class flixel.FlxCamera extends FlxBasic

Available on all platforms

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.

Class Fields

static var SHAKE_BOTH_AXES:Int

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

static var SHAKE_HORIZONTAL_ONLY:Int

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

static var SHAKE_VERTICAL_ONLY:Int

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

static var STYLE_LOCKON:Int

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

static var STYLE_NO_DEAD_ZONE:Int

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

static var STYLE_PLATFORMER:Int

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

static var STYLE_SCREEN_BY_SCREEN:Int

Camera "follow" style preset: camera will move screenwise.

static var STYLE_TOPDOWN:Int

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

static var STYLE_TOPDOWN_TIGHT:Int

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

static var defaultCameras:Array<FlxCamera>

Which cameras a FlxBasic uses to be drawn on when nothing else has been specified. * By default, this is just a reference to FlxG.cameras.list / all cameras, but it can be very useful to change.

static var defaultZoom:Float

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

Instance Fields

var alpha:Float

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

var angle:Float

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

var antialiasing:Bool

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

var bgColor:Int

The natural background color of the camera. Defaults to FlxG.cameras.bgColor. * NOTE: can be transparent for crazy FX (only works on flash)!

var bounds:FlxRect

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

var buffer:BitmapData

The actual bitmap data of the camera display itself.

var color:Int

The color tint of the camera display. * (Internal, help with color transforming the flash bitmap.)

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().

var flashSprite:Sprite

Used to render buffer to screen space. NOTE: We don't recommend modifying this directly unless you are fairly experienced. * Uses include 3D projection, advanced display list modification, and more.

var followLead:FlxPoint

Used to force the camera to look ahead of the target.

var followLerp:Float

Used to smoothly track the camera as it follows.

var height:Int

How tall the camera display is, in game pixels.

var regen:Bool

Whether checkResize checks if the camera dimensions have changed to update the buffer dimensions.

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.

var scroll:FlxPoint

Stores the basic parallax scrolling values.

var style:Int

Tells the camera to use this following style.

var target:FlxObject

Tells the camera to follow this FlxObject object around.

var useBgAlphaBlending:Bool

Whether to use alpha blending for camera's background fill or not. * Useful for flash target (and works only on this target). Default value is false.

var width:Int

How wide the camera display is, in game pixels.

var x:Float

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.

var y:Float

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

var zoom:Float

The zoom level of this camera. 1 = 1:1, 2 = 2x zoom, etc. * Indicates how far the camera is zoomed in.

function new(?X:Int = 0, ?Y:Int = 0, ?Width:Int = 0, ?Height:Int = 0, ?Zoom:Float = 0):Void

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

X

X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom. *

Y

Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom. *

Width

The width of the camera display in pixels. *

Height

The height of the camera display in pixels. *

Zoom

The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.

function checkResize():Void

function copyFrom(Camera:FlxCamera):FlxCamera

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

Camera

The camera you want to copy from. *

returns

A reference to this FlxCamera object.

function destroy():Void

Clean up memory.

function fade(?Color:Int = -16777216, ?Duration:Float = 1, ?FadeIn:Bool = false, ?OnComplete:Void ->Void = null, ?Force:Bool = false):Void

The screen is gradually filled with this color. * *

Color

The color you want to use. *

Duration

How long it takes for the fade to finish. *

FadeIn

True fades from a color, false fades to it. *

OnComplete

A function you want to run when the fade finishes. *

Force

Force the effect to reset.

function fill(Color:Int, ?BlendAlpha:Bool = true, ?FxAlpha:Float = 1.0f, ?graphics:Graphics = null):Void

Fill the camera with the specified color. * *

Color

The color to fill with in 0xAARRGGBB hex format. *

BlendAlpha

Whether to blend the alpha value or just wipe the previous contents. Default is true.

function flash(?Color:Int = -1, ?Duration:Float = 1, ?OnComplete:Void ->Void = null, ?Force:Bool = false):Void

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

Color

The color you want to use. *

Duration

How long it takes for the flash to fade. *

OnComplete

A function you want to run when the flash finishes. *

Force

Force the effect to reset.

function focusOn(point:FlxPoint):Void

Move the camera focus to this location instantly. * *

Point

Where you want the camera to focus.

function follow(Target:FlxObject, ?Style:Int = 0, ?Offset:FlxPoint = null, ?Lerp:Float = 0):Void

Tells this camera object what FlxObject to track. * *

Target

The object you want the camera to track. Set to null to not follow anything. *

Style

Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow(). *

Offset

Offset the follow deadzone by a certain amount. Only applicable for STYLEPLATFORMER and STYLELOCKON styles. *

Lerp

How much lag the camera should have (can help smooth out the camera movement).

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.

function setBounds(?X:Float = 0, ?Y:Float = 0, ?Width:Float = 0, ?Height:Float = 0, ?UpdateWorld:Bool = false):Void

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

X

The smallest X value of your level (usually 0). *

Y

The smallest Y value of your level (usually 0). *

Width

The largest X value of your level (usually the level width). *

Height

The largest Y value of your level (usually the level height). *

UpdateWorld

Whether the global quad-tree's dimensions should be updated to match (default: false).

function setPosition(?X:Float = 0, ?Y:Float = 0):Void

Helper function to set the coordinates of this camera. * Handy since it only requires one line of code. * *

X

The new x position *

Y

The new y position

function setScale(X:Float, Y:Float):Void

function setSize(Width:Int, Height:Int):Void

Shortcut for setting both width and Height. * *

Width

The new sprite width. *

Height

The new sprite height.

function shake(?Intensity:Float = 0.05f, ?Duration:Float = 0.5f, ?OnComplete:Void ->Void = null, ?Force:Bool = true, ?Direction:Int = 0):Void

A simple screen-shake effect. * *

Intensity

Percentage of screen size representing the maximum distance that the screen can move while shaking. *

Duration

The length in seconds that the shaking effect should last. *

OnComplete

A function you want to run when the shake effect finishes. *

Force

Force the effect to reset (default = true, unlike flash() and fade()!). *

Direction

Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKEBOTHAXES, SHAKEVERTICALONLY, or SHAKEHORIZONTALONLY).

function stopFX():Void

Just turns off all the camera effects instantly.

function update():Void

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