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)
Instantiates a new camera at the specified location, with the specified size and zoom level.
X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
The width of the camera display in pixels.
The height of the camera display in pixels.
The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.
The angle of the camera display (in degrees). Currently yields weird display results, since cameras aren't nested in an extra display object yet.
Whether the camera display is smooth and filtered, or chunky and pixelated. Default behavior is chunky-style.
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.
The actual bitmap data of the camera display itself. Used in blit render mode, where you can manipulate its pixels for achieving some visual effects.
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 unvisible). Its position is modified by updateInternalSpritePositions() method, which is called on camera's resize and scale events.
The color tint of the camera display. (Internal, help with color transforming the flash bitmap.)
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().
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 unvisible). Its position is modified by updateInternalSpritePositions() method, which is called on camera's resize and scale events.
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() method which is called every frame.
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 FlxG.updateFrameRate / 60 for consistency across framerates. The maximum value means no camera easing. A value of 0 means the camera does not move.
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.
Whether checkResize checks if the camera dimensions have changed to update the buffer dimensions.
The scaling on horizontal axis for this camera. Setting scaleX changes scaleX and x coordinate of camera's internal display objects (_flashBitmap, canvas and debugSprite).
The scaling on vertical axis for this camera. Setting scaleY changes scaleY and y coordinate of camera's internal display objects (_flashBitmap, canvas and debugSprite).
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 varible is used only in blit render mode.
FlxBloom demo shows how you can use this variable in blit render mode:
Stores the basic parallax scrolling values.
This is basically camera's top-left corner position in world coordinates.
There is also useful method
focusOn(point:FlxPoint) which you can use to make camera look at specified point in world coordinates.
Product of camera's scaleX and game's scalemode scale.x multiplication. Added this var for less calculations at rendering time (in tile render mode).
Product of camera's scaleY and game's scalemode scale.y multiplication. Added this var for less calculations at rendering time (in tile render mode).
Whether to use alpha blending for camera's background fill or not. If true then previosly 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:
The X position of this camera's display (used for positioning flashSprite of this camera). Zoom does NOT affect this number. Measured in pixels from the left side of the flash window. You might be interested in using camera's scroll.x instead.
The Y position of this camera's display (used for positioning flashSprite of this camera). Zoom does NOT affect this number. Measured in pixels from the top of the flash window. You might be interested in using camera's scroll.y instead.
Copy the bounds, focus object, and deadzone info from an existing camera.
The camera you want to copy from.
A reference to this FlxCamera object.
drawTriangles(graphic:FlxGraphic, vertices:DrawData<Float>, indices:DrawData<Int>, uvtData:DrawData<Float>, ?colors:DrawData<Int>, ?position:FlxPoint, ?blend:BlendMode, repeat:Bool = false, smoothing:Bool = false):Void
The screen is gradually filled with this color.
The color you want to use.
How long it takes for the fade to finish.
True fades from a color, false fades to it.
A function you want to run when the fade finishes.
Force the effect to reset.
Fill the camera with the specified color.
The color to fill with in 0xAARRGGBB hex format.
Whether to blend the alpha value or just wipe the previous contents. Default is true.
The screen is filled with this color and gradually returns to normal.
The color you want to use.
How long it takes for the flash to fade.
A function you want to run when the flash finishes.
Force the effect to reset.
Move the camera focus to this location instantly.
Where you want the camera to focus.
Tells this camera object what FlxObject to track.
The object you want the camera to track. Set to null to not follow anything.
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().
How much lag the camera should have (can help smooth out the camera movement).
Called by camera front end every time you resize the game. It triggers reposition of camera's internal display objects (flashSprite, _scrollRect, _flashBitmap, canvas, debugSprite).
Helper function to set the coordinates of this camera. Handy since it only requires one line of code.
The new x position
The new y position
Helper function to set the scale of this camera. Handy since it only requires one line of code.
The new scale on x axis
The new scale of y axis
Specify the bounds of where the camera is allowed to move. Set the boundary of a side to null to leave that side unbounded.
The minimum X value the camera can scroll to
The maximum X value the camera can scroll to
The minimum Y value the camera can scroll to
The maximum Y value the camera can scroll to
Specify the bounding rectangle of where the camera is allowed to move.
The smallest X value of your level (usually 0).
The smallest Y value of your level (usually 0).
The largest X value of your level (usually the level width).
The largest Y value of your level (usually the level height).
Whether the global quad-tree's dimensions should be updated to match (default: false).
Shortcut for setting both width and Height.
The new sprite width.
The new sprite height.
A simple screen-shake effect.
Percentage of screen size representing the maximum distance that the screen can move while shaking.
The length in seconds that the shaking effect should last.
A function you want to run when the shake effect finishes.
Force the effect to reset (default = true, unlike flash() and fade()!).
On what axes to shake. Default value is XY / both.
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.
Updates the camera scroll as well as special effects like screen-shake or fades.
Updates camera's scroll. Called every frame by camera's update() method (if camera's target isn't null).
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.