FlxZoomCamera: A FlxCamera that centers its zoom on the target that it follows
@link http://www.kwarp.com @email greg@kwarp.com
Constructor
Variables
@:value(0.25)zoomMargin:Float = 0.25
Determines how far to "look ahead" when the target is near the edge of the camera's bounds - 0 = no effect, 1 = huge effect
Methods
Inherited Variables
Defined by FlxCamera
@: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.
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(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(1)read onlyinitialZoom:Float = 1
Camera's initial zoom value. Used for camera's scale handling.
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.
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.
@: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.
5.2.0
.read onlyviewMarginBottom:Float
The margin cut off on the bottom by the camera zooming in (or out), in world space
5.2.0
.read onlyviewMarginLeft:Float
The margin cut off on the left by the camera zooming in (or out), in world space.
5.2.0
.read onlyviewMarginRight:Float
The margin cut off on the right by the camera zooming in (or out), in world space
5.2.0
.read onlyviewMarginTop:Float
The margin cut off on the top by the camera zooming in (or out), in world space
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.
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.
5.2.0
.@: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.
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)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).
cameras:Array<FlxCamera>
This determines on which FlxCamera
s 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
5.7.0
.Inherited Methods
Defined by FlxCamera
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
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.
4.3.0
.inlinecontainsRect(rect:FlxRect):Bool
Checks whether this camera contains a given rectangle, in screen coordinates.
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
@: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
@: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 |
---|---|
BlendAlpha | Whether to blend the alpha value or just wipe the previous contents. Default is |
@: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 |
---|---|
Style | Leverage one of the existing "deadzone" presets. Default is |
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
.
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.
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
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 |
---|---|
Y | The smallest Y value of your level (usually |
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: |
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 = |
Axes | On what axes to shake. Default value is |
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
.
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.
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.
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
.