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

Every camera has following display list: flashSprite:Sprite (which is a container for everything else in the camera, it's added to FlxG.game sprite)

|-> `_scrollRect:Sprite` (which is used for cropping camera's graphic, mostly in tile render mode)
    |-> `_flashBitmap:Bitmap`  (its bitmapData property is buffer BitmapData, this var is used in blit render mode.
                               Everything is rendered on buffer in blit render mode)
    |-> `canvas:Sprite`        (its graphics is used for rendering objects in tile render mode)
    |-> `debugLayer:Sprite`    (this sprite is used in tile render mode for rendering debug info, like bounding boxes)

Static variables

staticdefaultCameras:Array<FlxCamera>

Deprecated: "`FlxCamera.defaultCameras` is deprecated, use `FlxG.cameras.setDefaultDrawTarget` instead"

Used behind-the-scenes during the draw phase so that members use the same default cameras as their parent.

Prior to 4.9.0 it was useful to change this value, but that feature is deprecated. Instead use the defaultDrawTarget argument in FlxG.cameras.add . orFlxG.cameras.setDefaultDrawTarget .

See also:

  • FlxG.cameras.setDefaultDrawTarget

@:value(1.0)staticdefaultZoom:Float = 1.0

Any FlxCamera with a zoom of 0 (the default value) will have this zoom value.

Constructor

@:value({ Zoom : 0, Height : 0, Width : 0, Y : 0, X : 0 })new(X:Float = 0, Y:Float = 0, Width:Int = 0, Height:Int = 0, Zoom:Float = 0)

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

Parameters:

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.

Variables

@:value(1)alpha:Float = 1

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

@:value(0)angle:Float = 0

The angle of the camera display (in degrees).

@:value(false)antialiasing:Bool = false

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

bgColor:FlxColor

The natural background color of the camera, in AARRGGBB format. Defaults to FlxG.cameras.bgColor. On Flash, transparent backgrounds can be used in conjunction with useBgAlphaBlending.

buffer:BitmapData

The actual BitmapData of the camera display itself. Used in blit render mode, where you can manipulate its pixels for achieving some visual effects.

canvas:Sprite

Sprite used for actual rendering in tile render mode (instead of _flashBitmap for blitting). Its graphics is used as a drawing surface for drawTriangles() and drawTiles() methods. It is a child of _scrollRect Sprite (which trims graphics that should be invisible). Its position is modified by updateInternalSpritePositions(), which is called on camera's resize and scale events.

@:value(FlxColor.WHITE)color:FlxColor = FlxColor.WHITE

The color tint of the camera display.

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 camera bounds. 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. PLATFORMER) with follow().

debugLayer:Sprite

Sprite for visual effects (flash and fade) and drawDebug information (bounding boxes are drawn on it) for tile render mode. It is a child of _scrollRect Sprite (which trims graphics that should be invisible). Its position is modified by updateInternalSpritePositions(), which is called on camera's resize and scale events.

@:value(null)filters:Null<Array<BitmapFilter>> = null

The filters array to be applied to the camera.

@:value(true)filtersEnabled:Bool = true

Enables or disables the filters set via setFilters().

@:value(new Sprite())flashSprite:Sprite = new 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. This is container for everything else that is used by camera and rendered to the camera.

Its position is modified by updateFlashSpritePosition() which is called every frame.

@:value(FlxPoint.get())read onlyfollowLead:FlxPoint = FlxPoint.get()

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

@:value(60 / FlxG.updateFramerate)followLerp:Float = 60 / FlxG.updateFramerate

Used to smoothly track the camera as it follows: The percent of the distance to the follow target the camera moves per 1/60 sec. Values are bounded between 0.0 and 60 / FlxG.updateFramerate for consistency across framerates. The maximum value means no camera easing. A value of 0 means the camera does not move.

@:value(0)height:Int = 0

How tall the camera display is, in game pixels.

@:value(1)read onlyinitialZoom:Float = 1

Camera's initial zoom value. Used for camera's scale handling.

maxScrollX:Null<Float>

Upper bound of the camera's scroll on the x axis.

maxScrollY:Null<Float>

Upper bound of the camera's scroll on the y axis.

minScrollX:Null<Float>

Lower bound of the camera's scroll on the x axis.

minScrollY:Null<Float>

Lower bound of the camera's scroll on the y axis.

pixelPerfectRender:Bool

Whether the positions of the objects rendered on this camera are rounded. If set on individual objects, they ignore the global camera setting. Defaults to false with FlxG.renderTile and to true with FlxG.renderBlit. WARNING: setting this to false on blitting targets is very expensive.

@:value(null)pixelPerfectShake:Null<Bool> = null

If true, screen shake will be rounded to game pixels. If null, pixelPerfectRender is used.

Available since

5.4.0

.

@:value(0)read onlyscaleX:Float = 0

The scaling on horizontal axis for this camera. Setting scaleX changes scaleX and x coordinate of camera's internal display objects.

@:value(0)read onlyscaleY:Float = 0

The scaling on vertical axis for this camera. Setting scaleY changes scaleY and y coordinate of camera's internal display objects.

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. Basically this sprite's pixels property is camera's BitmapData buffer. NOTE: This variable is used only in blit render mode.

The FlxBloom demo shows how you can use this variable in blit render mode.

See also:

@:value(FlxPoint.get())scroll:FlxPoint = FlxPoint.get()

Stores the basic parallax scrolling values. This is basically the camera's top-left corner position in world coordinates. There is also focusOn(point:FlxPoint) which you can use to make the camera look at specified point in world coordinates.

style:FlxCameraFollowStyle

Tells the camera to use this following style.

target:FlxObject

Tells the camera to follow this FlxObject object around.

@:value(FlxPoint.get())read onlytargetOffset:FlxPoint = FlxPoint.get()

Offset the camera target.

read onlytotalScaleX:Float

Product of camera's scaleX and game's scale mode scale.x multiplication.

read onlytotalScaleY:Float

Product of camera's scaleY and game's scale mode scale.y multiplication.

@:value(false)useBgAlphaBlending:Bool = false

Whether to use alpha blending for camera's background fill or not. If true then previously drawn graphics won't be erased, and if camera's bgColor is transparent/semitransparent then you will be able to see graphics of the previous frame. Useful for blit render mode (and works only in this mode). Default value is false.

Usage example can be seen in FlxBloom demo.

See also:

read onlyviewBottom:Float

The bottom side of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewHeight:Float

The size of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewLeft:Float

The left of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewMarginBottom:Float

The margin cut off on the bottom by the camera zooming in (or out), in world space

Available since

5.2.0

.

read onlyviewMarginLeft:Float

The margin cut off on the left by the camera zooming in (or out), in world space.

Available since

5.2.0

.

read onlyviewMarginRight:Float

The margin cut off on the right by the camera zooming in (or out), in world space

Available since

5.2.0

.

read onlyviewMarginTop:Float

The margin cut off on the top by the camera zooming in (or out), in world space

Available since

5.2.0

.

read onlyviewMarginX:Float

The margin cut off on the left and right by the camera zooming in (or out), in world space.

Available since

5.2.0

.

read onlyviewMarginY:Float

The margin cut off on the top and bottom by the camera zooming in (or out), in world space.

Available since

5.2.0

.

read onlyviewRight:Float

The right side of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewTop:Float

The top of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewWidth:Float

The size of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewX:Float

The left of the camera's view, in world space.

Available since

5.2.0

.

read onlyviewY:Float

The top of the camera's view, in world space.

Available since

5.2.0

.

@:value(0)width:Int = 0

How wide the camera display is, in game pixels.

@:value(0)x:Float = 0

The X position of this camera's display. zoom does NOT affect this number. Measured in pixels from the left side of the window. You might be interested in using camera's scroll.x instead.

@:value(0)y:Float = 0

The Y position of this camera's display. zoom does NOT affect this number. Measured in pixels from the top of the window. You might be interested in using camera's scroll.y instead.

zoom:Float

The zoom level of this camera. 1 = 1:1, 2 = 2x zoom, etc. Indicates how far the camera is zoomed in. Note: Changing this property from it's initial value will change properties like: viewX, viewY, viewWidth, viewHeight and many others. Cameras always zoom in to their center, meaning as you zoom in, the view is cut off on all sides.

Methods

bindScrollPos(scrollPos:FlxPoint):FlxPoint

Takes the desired scroll position and restricts it to the camera's min/max scroll properties. This modifies the given point.

Parameters:

scrollPos

The scroll position

Returns:

The same point passed in, moved within the scroll bounds

Available since

5.4.0

.

@:value({ height : 0, width : 0 })inlinecontainsPoint(point:FlxPoint, width:Float = 0, height:Float = 0):Bool

Checks whether this camera contains a given point or rectangle, in screen coordinates.

Available since

4.3.0

.

inlinecontainsRect(rect:FlxRect):Bool

Checks whether this camera contains a given rectangle, in screen coordinates.

Available since

4.11.0

.

copyFrom(Camera:FlxCamera):FlxCamera

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

Parameters:

Camera

The camera you want to copy from.

Returns:

A reference to this FlxCamera object.

@:value({ smoothing : false })copyPixels(?frame:FlxFrame, ?pixels:BitmapData, ?sourceRect:Null<Rectangle>, destPoint:Point, ?transform:Null<ColorTransform>, ?blend:Null<BlendMode>, smoothing:Bool = false, ?shader:Null<FlxShader>):Void

destroy():Void

Clean up memory.

@:value({ smoothing : false })drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:Null<ColorTransform>, ?blend:Null<BlendMode>, smoothing:Bool = false, ?shader:Null<FlxShader>):Void

@:value({ smoothing : false, repeat : false })drawTriangles(graphic:FlxGraphic, vertices:DrawData<Float>, indices:DrawData<Int>, uvtData:DrawData<Float>, ?colors:DrawData<Int>, ?position:FlxPoint, ?blend:Null<BlendMode>, repeat:Bool = false, smoothing:Bool = false, ?transform:Null<ColorTransform>, ?shader:Null<FlxShader>):Void

@:value({ Force : false, FadeIn : false, Duration : 1, Color : FlxColor.BLACK })fade(Color:FlxColor = FlxColor.BLACK, Duration:Float = 1, FadeIn:Bool = false, ?OnComplete:() ‑> Void, Force:Bool = false):Void

The screen is gradually filled with this color.

Parameters:

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.

@:value({ FxAlpha : 1.0, BlendAlpha : true })fill(Color:FlxColor, BlendAlpha:Bool = true, FxAlpha:Float = 1.0, ?graphics:Null<Graphics>):Void

Fill the camera with the specified color.

Parameters:

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.

@:value({ Force : false, Duration : 1, Color : FlxColor.WHITE })flash(Color:FlxColor = FlxColor.WHITE, Duration:Float = 1, ?OnComplete:() ‑> Void, Force:Bool = false):Void

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

Parameters:

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.

inlinefocusOn(point:FlxPoint):Void

Move the camera focus to this location instantly.

Parameters:

Point

Where you want the camera to focus.

follow(Target:FlxObject, ?Style:FlxCameraFollowStyle, ?Lerp:Float):Void

Tells this camera object what FlxObject to track.

Parameters:

Target

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

Style

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

Lerp

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

getViewMarginRect(?rect:FlxRect):FlxRect

The size and position of this camera's margins, via viewMarginLeft, viewMarginTop, viewWidth and viewHeight.

Available since

5.2.0

.

@deprecated("getViewMarginRect")getViewRect(?rect:FlxRect):FlxRect

The size and position of this camera's margins, via viewMarginLeft, viewMarginTop, viewWidth and viewHeight.

Notes: Deprecated, in 4.11.0 this was made public, but the wording is confusing. In flixel 6.0.0 this will be changed to use viewX, viewY, viewWidth and viewHeight, meaning, this will return the world coordinates of the camera.

Available since

4.11.0

.

onResize():Void

Called by camera front end every time you resize the game. It triggers reposition of camera's internal display objects.

setFilters(filters:Array<BitmapFilter>):Void

Deprecated: "setFilters() is deprecated, use the filters array instead"

Sets the filter array to be applied to the camera.

@:value({ Y : 0, X : 0 })inlinesetPosition(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.

Parameters:

X

The new x position.

Y

The new y position.

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

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

Parameters:

X

The new scale on x axis

Y

The new scale of y axis

setScrollBounds(MinX:Null<Float>, MaxX:Null<Float>, MinY:Null<Float>, MaxY:Null<Float>):Void

Specify the bounds of where the camera is allowed to move. Set the boundary of a side to null to leave that side unbounded.

Parameters:

MinX

The minimum X value the camera can scroll to

MaxX

The maximum X value the camera can scroll to

MinY

The minimum Y value the camera can scroll to

MaxY

The maximum Y value the camera can scroll to

@:value({ UpdateWorld : false, Height : 0, Width : 0, Y : 0, X : 0 })setScrollBoundsRect(X:Float = 0, Y:Float = 0, Width:Float = 0, Height:Float = 0, UpdateWorld:Bool = false):Void

Specify the bounding rectangle of where the camera is allowed to move.

Parameters:

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

inlinesetSize(Width:Int, Height:Int):Void

Shortcut for setting both width and height.

Parameters:

Width

The new camera width.

Height

The new camera height.

@:value({ Force : true, Duration : 0.5, Intensity : 0.05 })shake(Intensity:Float = 0.05, Duration:Float = 0.5, ?OnComplete:() ‑> Void, Force:Bool = true, ?Axes:FlxAxes):Void

A simple screen-shake effect.

Parameters:

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

Axes

On what axes to shake. Default value is FlxAxes.XY / both.

snapToTarget():Void

Snaps the camera to the current target. Useful to move the camera without any easing when the target position changes and there is a followLerp.

stopFX():Void

Stops all effects on this camera.

stopFade():Void

Stops the fade effect on this camera.

stopFlash():Void

Stops the flash effect on this camera.

stopShake():Void

Stops the shake effect on this camera.

update(elapsed:Float):Void

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

updateFollow():Void

Updates camera's scroll. Called every frame by camera's update() method (if camera's target isn't null).

updateScroll():Void

Updates (bounds) the camera scroll. Called every frame by camera's update() method.

Inherited Variables

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxBasic

draw():Void

Override this function to control how the object is drawn. Doing so is rarely necessary, but can be very useful.

getCameras():Array<FlxCamera>

The cameras that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's cameras are used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then the default draw cameras are returned.

Available since

5.7.0

.

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().