Class: Camera

Phaser.Cameras.Scene2D. Camera

A Camera.

The Camera is the way in which all games are rendered in Phaser. They provide a view into your game world, and can be positioned, rotated, zoomed and scrolled accordingly.

A Camera consists of two elements: The viewport and the scroll values.

The viewport is the physical position and size of the Camera within your game. Cameras, by default, are created the same size as your game, but their position and size can be set to anything. This means if you wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game, you'd adjust the viewport to do that (using methods like setViewport and setSize).

If you wish to change where the Camera is looking in your game, then you scroll it. You can do this via the properties scrollX and scrollY or the method setScroll. Scrolling has no impact on the viewport, and changing the viewport has no impact on the scrolling.

By default a Camera will render all Game Objects it can see. You can change this using the ignore method, allowing you to filter Game Objects out on a per-Camera basis.

A Camera also has built-in special effects including Fade, Flash and Camera Shake.


new Camera(x, y, width, height)

Parameters:
Name Type Description
x number

The x position of the Camera, relative to the top-left of the game canvas.

y number

The y position of the Camera, relative to the top-left of the game canvas.

width number

The width of the Camera, in pixels.

height number

The height of the Camera, in pixels.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 18)

Extends

Members


alpha :number

The Camera alpha value. Setting this property impacts every single object that this Camera renders. You can either set the property directly, i.e. via a Tween, to fade a Camera in or out, or via the chainable setAlpha method instead.

Type:
  • number
Since: 3.11.0
Inherited From:
Default Value:
  • 1
Source: src/cameras/2d/BaseCamera.js (Line 411)

alphaBottomLeft :number

The alpha value starting from the bottom-left of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 227)

alphaBottomRight :number

The alpha value starting from the bottom-right of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 257)

alphaTopLeft :number

The alpha value starting from the top-left of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 167)

alphaTopRight :number

The alpha value starting from the top-right of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 197)

backgroundColor :Phaser.Display.Color

The background color of this Camera. Only used if transparent is false.

Type:
Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 402)

cameraManager :Phaser.Cameras.Scene2D.CameraManager

A reference to the Scene's Camera Manager to which this Camera belongs.

Type:
Since: 3.17.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 106)

canvas :HTMLCanvasElement

If this Camera has been set to render to a texture then this holds a reference to the HTML Canvas Element that the Camera is drawing to.

Enable texture rendering using the method setRenderToTexture.

This is only populated if Phaser is running with the Canvas Renderer.

Type:
  • HTMLCanvasElement
Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 211)

<readonly> centerX :number

The horizontal position of the center of the Camera's viewport, relative to the left of the game canvas.

Type:
  • number
Since: 3.10.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1833)

<readonly> centerY :number

The vertical position of the center of the Camera's viewport, relative to the top of the game canvas.

Type:
  • number
Since: 3.10.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1850)

context :CanvasRenderingContext2D

If this Camera has been set to render to a texture then this holds a reference to the Rendering Context belonging to the Canvas element the Camera is drawing to.

Enable texture rendering using the method setRenderToTexture.

This is only populated if Phaser is running with the Canvas Renderer.

Type:
  • CanvasRenderingContext2D
Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 225)

<nullable> deadzone :Phaser.Geom.Rectangle

The Camera dead zone.

The deadzone is only used when the camera is following a target.

It defines a rectangular region within which if the target is present, the camera will not scroll. If the target moves outside of this area, the camera will begin scrolling in order to follow it.

The lerp values that you can set for a follower target also apply when using a deadzone.

You can directly set this property to be an instance of a Rectangle. Or, you can use the setDeadzone method for a chainable approach.

The rectangle you provide can have its dimensions adjusted dynamically, however, please note that its position is updated every frame, as it is constantly re-centered on the cameras mid point.

Calling setDeadzone with no arguments will reset an active deadzone, as will setting this property to null.

Type:
Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 159)

dirty :boolean

Is this Camera dirty?

A dirty Camera has had either its viewport size, bounds, scroll, rotation or zoom levels changed since the last frame.

This flag is cleared during the postRenderCamera method of the renderer.

Type:
  • boolean
Since: 3.11.0
Inherited From:
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 196)

disableCull :boolean

Should the camera cull Game Objects before checking them for input hit tests? In some special cases it may be beneficial to disable this.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 422)

<readonly> displayHeight :number

The displayed height of the camera viewport, factoring in the camera zoom level.

If a camera has a viewport height of 600 and a zoom of 0.5 then its display height would be 1200, as it's displaying twice as many pixels as zoom level 1.

Equally, a camera with a height of 600 and zoom of 2 would have a display height of 300 pixels.

Type:
  • number
Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1890)

<readonly> displayWidth :number

The displayed width of the camera viewport, factoring in the camera zoom level.

If a camera has a viewport width of 800 and a zoom of 0.5 then its display width would be 1600, as it's displaying twice as many pixels as zoom level 1.

Equally, a camera with a width of 800 and zoom of 2 would have a display width of 400 pixels.

Type:
  • number
Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1867)

fadeEffect :Phaser.Cameras.Scene2D.Effects.Fade

The Camera Fade effect handler. To fade this camera see the Camera.fade methods.

Type:
Since: 3.5.0
Source: src/cameras/2d/Camera.js (Line 80)

flashEffect :Phaser.Cameras.Scene2D.Effects.Flash

The Camera Flash effect handler. To flash this camera see the Camera.flash method.

Type:
Since: 3.5.0
Source: src/cameras/2d/Camera.js (Line 90)

flipX :boolean

The horizontally flipped state of the Game Object. A Game Object that is flipped horizontally will render inversed on the horizontal axis. Flipping always takes place from the middle of the texture and does not impact the scale value.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/components/Flip.js (Line 17)

flipY :boolean

The vertically flipped state of the Game Object. A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) Flipping always takes place from the middle of the texture and does not impact the scale value.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/components/Flip.js (Line 29)

followOffset :Phaser.Math.Vector2

The values stored in this property are subtracted from the Camera targets position, allowing you to offset the camera from the actual target x/y coordinates by this amount. Can also be set via setFollowOffset or as part of the startFollow call.

Type:
Since: 3.9.0
Source: src/cameras/2d/Camera.js (Line 148)

<nullable> framebuffer :WebGLFramebuffer

If this Camera has been set to render to a texture then this holds a reference to the GL Frame Buffer belonging the Camera is drawing to.

Enable texture rendering using the method setRenderToTexture.

This is only set if Phaser is running with the WebGL Renderer.

Type:
  • WebGLFramebuffer
Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 253)

<nullable> glTexture :WebGLTexture

If this Camera has been set to render to a texture then this holds a reference to the GL Texture belonging the Camera is drawing to.

Enable texture rendering using the method setRenderToTexture.

This is only set if Phaser is running with the WebGL Renderer.

Type:
  • WebGLTexture
Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 239)

height :number

The height of the Camera viewport, in pixels.

The viewport is the area into which the Camera renders. Setting the viewport does not restrict where the Camera can scroll to.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1686)

<readonly> id :integer

The Camera ID. Assigned by the Camera Manager and used to handle camera exclusion. This value is a bitmask.

Type:
  • integer
Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 115)

inputEnabled :boolean

Does this Camera allow the Game Objects it renders to receive input events?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/cameras/2d/Camera.js (Line 70)

<readonly> isTinted :boolean

Does this Game Object have a tint applied to it or not?

Type:
  • boolean
Since: 3.11.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 313)

lerp :Phaser.Math.Vector2

The linear interpolation value to use when following a target.

Can also be set via setLerp or as part of the startFollow call.

The default values of 1 means the camera will instantly snap to the target coordinates. A lower value, such as 0.1 means the camera will more slowly track the target, giving a smooth transition. You can set the horizontal and vertical values independently, and also adjust this value in real-time during your game.

Be sure to keep the value between 0 and 1. A value of zero will disable tracking on that axis.

Type:
Since: 3.9.0
Source: src/cameras/2d/Camera.js (Line 130)

<nullable> mask :Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask

The Mask this Camera is using during render. Set the mask using the setMask method. Remove the mask using the clearMask method.

Type:
Since: 3.17.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 504)

<readonly> midPoint :Phaser.Math.Vector2

The mid-point of the Camera in 'world' coordinates.

Use it to obtain exactly where in the world the center of the camera is currently looking.

This value is updated in the preRender method, after the scroll values and follower have been processed.

Type:
Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 444)

name :string

The name of the Camera. This is left empty for your own use.

Type:
  • string
Since: 3.0.0
Inherited From:
Default Value:
  • ''
Source: src/cameras/2d/BaseCamera.js (Line 126)

originX :number

The horizontal origin of rotation for this Camera.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens. A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

See setOrigin to set both origins in a single, chainable call.

Type:
  • number
Since: 3.11.0
Inherited From:
Default Value:
  • 0.5
Source: src/cameras/2d/BaseCamera.js (Line 459)

originY :number

The vertical origin of rotation for this Camera.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens. A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

See setOrigin to set both origins in a single, chainable call.

Type:
  • number
Since: 3.11.0
Inherited From:
Default Value:
  • 0.5
Source: src/cameras/2d/BaseCamera.js (Line 476)

panEffect :Phaser.Cameras.Scene2D.Effects.Pan

The Camera Pan effect handler. To pan this camera see the Camera.pan method.

Type:
Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 110)

pipeline :any

If this Camera has been set to render to a texture and to use a custom pipeline, then this holds a reference to the pipeline the Camera is drawing with.

Enable texture rendering using the method setRenderToTexture.

This is only set if Phaser is running with the WebGL Renderer.

Type:
  • any
Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 267)

renderToTexture :boolean

Is this Camera rendering directly to the canvas or to a texture?

Enable rendering to texture with the method setRenderToTexture (just enabling this boolean won't be enough)

Once enabled you can toggle it by switching this property.

To properly remove a render texture you should call the clearRenderToTexture() method.

Type:
  • boolean
Since: 3.13.0
Default Value:
  • false
Source: src/cameras/2d/Camera.js (Line 195)

<readonly> resolution :number

This property is un-used in v3.16.

The resolution of the Game, used in most Camera calculations.

Type:
  • number
Since: 3.12.0
Inherited From:
Deprecated:
  • Yes
Source: src/cameras/2d/BaseCamera.js (Line 136)

roundPixels :boolean

Should this camera round its pixel values to integers?

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 149)

scaleManager :Phaser.Scale.ScaleManager

A reference to the Game Scale Manager.

Type:
Since: 3.16.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 97)

scene :Phaser.Scene

A reference to the Scene this camera belongs to.

Type:
Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 79)

sceneManager :Phaser.Scenes.SceneManager

A reference to the Game Scene Manager.

Type:
Since: 3.12.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 88)

scrollX :number

The horizontal scroll position of this Camera.

Change this value to cause the Camera to scroll around your Scene.

Alternatively, setting the Camera to follow a Game Object, via the startFollow method, will automatically adjust the Camera scroll values accordingly.

You can set the bounds within which the Camera can scroll via the setBounds method.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 0
Source: src/cameras/2d/BaseCamera.js (Line 1712)

scrollY :number

The vertical scroll position of this Camera.

Change this value to cause the Camera to scroll around your Scene.

Alternatively, setting the Camera to follow a Game Object, via the startFollow method, will automatically adjust the Camera scroll values accordingly.

You can set the bounds within which the Camera can scroll via the setBounds method.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 0
Source: src/cameras/2d/BaseCamera.js (Line 1742)

shakeEffect :Phaser.Cameras.Scene2D.Effects.Shake

The Camera Shake effect handler. To shake this camera see the Camera.shake method.

Type:
Since: 3.5.0
Source: src/cameras/2d/Camera.js (Line 100)

tint :integer

The tint value being applied to the whole of the Game Object.

Type:
  • integer
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 297)

tintBottomLeft :integer

The tint value being applied to the bottom-left of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • integer
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 249)

tintBottomRight :integer

The tint value being applied to the bottom-right of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • integer
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 273)

tintFill :boolean

Fill or additive?

Type:
  • boolean
Since: 3.11.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/components/Tint.js (Line 83)

tintTopLeft :integer

The tint value being applied to the top-left of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • integer
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 201)

tintTopRight :integer

The tint value being applied to the top-right of the Game Object. This value is interpolated from the corner to the center of the Game Object.

Type:
  • integer
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 225)

transparent :boolean

Does this Camera have a transparent background?

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 392)

useBounds :boolean

Is this Camera using a bounds to restrict scrolling movement?

Set this property along with the bounds via Camera.setBounds.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 171)

visible :boolean

Is this Camera visible or not?

A visible camera will render and perform input tests. An invisible camera will not render anything and will skip input tests.

Type:
  • boolean
Since: 3.10.0
Inherited From:
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 159)

width :number

The width of the Camera viewport, in pixels.

The viewport is the area into which the Camera renders. Setting the viewport does not restrict where the Camera can scroll to.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1660)

<readonly> worldView :Phaser.Geom.Rectangle

The World View is a Rectangle that defines the area of the 'world' the Camera is currently looking at. This factors in the Camera viewport size, zoom and scroll position and is updated in the Camera preRender step. If you have enabled Camera bounds the worldview will be clamped to those bounds accordingly. You can use it for culling or intersection checks.

Type:
Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 183)

zoom :number

The Camera zoom value. Change this value to zoom in, or out of, a Scene.

A value of 0.5 would zoom the Camera out, so you can now see twice as much of the Scene as before. A value of 2 would zoom the Camera in, so every pixel now takes up 2 pixels when rendered.

Set to 1 to return to the default zoom level.

Be careful to never set this value to zero.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 1
Source: src/cameras/2d/BaseCamera.js (Line 1772)

zoomEffect :Phaser.Cameras.Scene2D.Effects.Zoom

The Camera Zoom effect handler. To zoom this camera see the Camera.zoom method.

Type:
Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 120)

Methods


addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Events.EventEmitter

centerOn(x, y)

Moves the Camera so that it is centered on the given coordinates, bounds allowing.

Parameters:
Name Type Description
x number

The horizontal coordinate to center on.

y number

The vertical coordinate to center on.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 657)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerOnX(x)

Moves the Camera horizontally so that it is centered on the given x coordinate, bounds allowing. Calling this does not change the scrollY value.

Parameters:
Name Type Description
x number

The horizontal coordinate to center on.

Since: 3.16.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 603)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerOnY(y)

Moves the Camera vertically so that it is centered on the given y coordinate, bounds allowing. Calling this does not change the scrollX value.

Parameters:
Name Type Description
y number

The vertical coordinate to center on.

Since: 3.16.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 630)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerToBounds()

Moves the Camera so that it is looking at the center of the Camera Bounds, if enabled.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 676)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerToSize()

Moves the Camera so that it is re-centered based on its viewport size.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 701)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

clampX(x)

Takes an x value and checks it's within the range of the Camera bounds, adjusting if required. Do not call this method if you are not using camera bounds.

Parameters:
Name Type Description
x number

The value to horizontally scroll clamp.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 970)
Returns:

The adjusted value to use as scrollX.

Type
number

clampY(y)

Takes a y value and checks it's within the range of the Camera bounds, adjusting if required. Do not call this method if you are not using camera bounds.

Parameters:
Name Type Description
y number

The value to vertically scroll clamp.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1002)
Returns:

The adjusted value to use as scrollY.

Type
number

clearAlpha()

Clears all alpha values associated with this Game Object.

Immediately sets the alpha levels back to 1 (fully opaque).

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 77)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

clearMask( [destroyMask])

Clears the mask that this Camera was using.

Parameters:
Name Type Argument Default Description
destroyMask boolean <optional>
false

Destroy the mask before clearing it?

Since: 3.17.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1451)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

clearRenderToTexture()

If this Camera was set to render to a texture, this will clear the resources it was using and redirect it to render back to the primary Canvas again.

If you only wish to temporarily disable rendering to a texture then you can toggle the property renderToTexture instead.

Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 378)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

clearTint()

Clears all tint values associated with this Game Object.

Immediately sets the color values back to 0xffffff and the tint type to 'additive', which results in no visible change to the texture.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 93)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

cull(renderableObjects)

Takes an array of Game Objects and returns a new array featuring only those objects visible by this camera.

Parameters:
Name Type Description
renderableObjects Array.<Phaser.GameObjects.GameObject>

An array of Game Objects to cull.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 717)
Returns:

An array of Game Objects visible to this Camera.

Type
Array.<Phaser.GameObjects.GameObject>

destroy()

Destroys this Camera instance. You rarely need to call this directly.

Called by the Camera Manager. If you wish to destroy a Camera please use CameraManager.remove as cameras are stored in a pool, ready for recycling later, and calling this directly will prevent that.

Since: 3.0.0
Overrides:
Source: src/cameras/2d/Camera.js (Line 957)
Fires:

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
array

fade( [duration] [, red] [, green] [, blue] [, force] [, callback] [, context])

Fades the Camera from transparent to the given color over the duration specified.

Parameters:
Name Type Argument Default Description
duration integer <optional>
1000

The duration of the effect in milliseconds.

red integer <optional>
0

The amount to fade the red channel towards. A value between 0 and 255.

green integer <optional>
0

The amount to fade the green channel towards. A value between 0 and 255.

blue integer <optional>
0

The amount to fade the blue channel towards. A value between 0 and 255.

force boolean <optional>
false

Force the effect to start immediately, even if already running.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 561)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

fadeFrom( [duration] [, red] [, green] [, blue] [, force] [, callback] [, context])

Fades the Camera from the given color to transparent over the duration specified.

Parameters:
Name Type Argument Default Description
duration integer <optional>
1000

The duration of the effect in milliseconds.

red integer <optional>
0

The amount to fade the red channel towards. A value between 0 and 255.

green integer <optional>
0

The amount to fade the green channel towards. A value between 0 and 255.

blue integer <optional>
0

The amount to fade the blue channel towards. A value between 0 and 255.

force boolean <optional>
false

Force the effect to start immediately, even if already running.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.5.0
Source: src/cameras/2d/Camera.js (Line 537)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

fadeIn( [duration] [, red] [, green] [, blue] [, callback] [, context])

Fades the Camera in from the given color over the duration specified.

Parameters:
Name Type Argument Default Description
duration integer <optional>
1000

The duration of the effect in milliseconds.

red integer <optional>
0

The amount to fade the red channel towards. A value between 0 and 255.

green integer <optional>
0

The amount to fade the green channel towards. A value between 0 and 255.

blue integer <optional>
0

The amount to fade the blue channel towards. A value between 0 and 255.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.3.0
Source: src/cameras/2d/Camera.js (Line 490)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

fadeOut( [duration] [, red] [, green] [, blue] [, callback] [, context])

Fades the Camera out to the given color over the duration specified. This is an alias for Camera.fade that forces the fade to start, regardless of existing fades.

Parameters:
Name Type Argument Default Description
duration integer <optional>
1000

The duration of the effect in milliseconds.

red integer <optional>
0

The amount to fade the red channel towards. A value between 0 and 255.

green integer <optional>
0

The amount to fade the green channel towards. A value between 0 and 255.

blue integer <optional>
0

The amount to fade the blue channel towards. A value between 0 and 255.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.3.0
Source: src/cameras/2d/Camera.js (Line 513)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

flash( [duration] [, red] [, green] [, blue] [, force] [, callback] [, context])

Flashes the Camera by setting it to the given color immediately and then fading it away again quickly over the duration specified.

Parameters:
Name Type Argument Default Description
duration integer <optional>
250

The duration of the effect in milliseconds.

red integer <optional>
255

The amount to fade the red channel towards. A value between 0 and 255.

green integer <optional>
255

The amount to fade the green channel towards. A value between 0 and 255.

blue integer <optional>
255

The amount to fade the blue channel towards. A value between 0 and 255.

force boolean <optional>
false

Force the effect to start immediately, even if already running.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 585)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

getBounds( [out])

Returns a rectangle containing the bounds of the Camera.

If the Camera does not have any bounds the rectangle will be empty.

The rectangle is a copy of the bounds, so is safe to modify.

Parameters:
Name Type Argument Description
out Phaser.Geom.Rectangle <optional>

An optional Rectangle to store the bounds in. If not given, a new Rectangle will be created.

Since: 3.16.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1157)
Returns:

A rectangle containing the bounds of this Camera.

Type
Phaser.Geom.Rectangle

getScroll(x, y [, out])

Calculates what the Camera.scrollX and scrollY values would need to be in order to move the Camera so it is centered on the given x and y coordinates, without actually moving the Camera there. The results are clamped based on the Camera bounds, if set.

Parameters:
Name Type Argument Description
x number

The horizontal coordinate to center on.

y number

The vertical coordinate to center on.

out Phaser.Math.Vector2 <optional>

A Vec2 to store the values in. If not given a new Vec2 is created.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 570)
Returns:

The scroll coordinates stored in the x and y properties.

Type
Phaser.Math.Vector2

getWorldPoint(x, y [, output])

Converts the given x and y coordinates into World space, based on this Cameras transform. You can optionally provide a Vector2, or similar object, to store the results in.

Parameters:
Name Type Argument Description
x number

The x position to convert to world space.

y number

The y position to convert to world space.

output object | Phaser.Math.Vector2 <optional>

An optional object to store the results in. If not provided a new Vector2 will be created.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 798)
Returns:

An object holding the converted values in its x and y properties.

Type
Phaser.Math.Vector2

ignore(entries)

Given a Game Object, or an array of Game Objects, it will update all of their camera filter settings so that they are ignored by this Camera. This means they will not be rendered by this Camera.

Parameters:
Name Type Description
entries Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | Phaser.GameObjects.Group

The Game Object, or array of Game Objects, to be ignored by this Camera.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 866)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
array

off(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Events.EventEmitter

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Events.EventEmitter

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Events.EventEmitter

pan(x, y [, duration] [, ease] [, force] [, callback] [, context])

This effect will scroll the Camera so that the center of its viewport finishes at the given destination, over the duration and with the ease specified.

Parameters:
Name Type Argument Default Description
x number

The destination x coordinate to scroll the center of the Camera viewport to.

y number

The destination y coordinate to scroll the center of the Camera viewport to.

duration integer <optional>
1000

The duration of the effect in milliseconds.

ease string | function <optional>
'Linear'

The ease to use for the pan. Can be any of the Phaser Easing constants or a custom function.

force boolean <optional>
false

Force the pan effect to start immediately, even if already running.

callback Phaser.Types.Cameras.Scene2D.CameraPanCallback <optional>

This callback will be invoked every frame for the duration of the effect. It is sent four arguments: A reference to the camera, a progress amount between 0 and 1 indicating how complete the effect is, the current camera scroll x coordinate and the current camera scroll y coordinate.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 631)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

<protected> preRender(resolution)

Internal preRender step.

Parameters:
Name Type Description
resolution number

The game resolution, as set in the Scale Manager.

Since: 3.0.0
Overrides:
Source: src/cameras/2d/Camera.js (Line 681)

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Events.EventEmitter

removeBounds()

If this Camera has previously had movement bounds set on it, this will remove them.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1039)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

removeListener(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Events.EventEmitter

resetFlip()

Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 124)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

resetFX()

Resets any active FX, such as a fade, flash or shake. Useful to call after a fade in order to remove the fade.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 916)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setAlpha( [value])

Set the Alpha level of this Camera. The alpha controls the opacity of the Camera as it renders. Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque.

Parameters:
Name Type Argument Default Description
value number <optional>
1

The Camera alpha value.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 529)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setAngle( [value])

Set the rotation of this Camera. This causes everything it renders to appear rotated.

Rotating a camera does not rotate the viewport itself, it is applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The cameras angle of rotation, given in degrees.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1058)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setBackgroundColor( [color])

Sets the background color for this Camera.

By default a Camera has a transparent background but it can be given a solid color, with any level of transparency, via this method.

The color value can be specified using CSS color notation, hex or numbers.

Parameters:
Name Type Argument Default Description
color string | number | Phaser.Types.Display.InputColorObject <optional>
'rgba(0,0,0,0)'

The color value. In CSS, hex or numeric color notation.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1079)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setBounds(x, y, width, height [, centerOn])

Set the bounds of the Camera. The bounds are an axis-aligned rectangle.

The Camera bounds controls where the Camera can scroll to, stopping it from scrolling off the edges and into blank space. It does not limit the placement of Game Objects, or where the Camera viewport can be positioned.

Temporarily disable the bounds by changing the boolean Camera.useBounds.

Clear the bounds entirely by calling Camera.removeBounds.

If you set bounds that are smaller than the viewport it will stop the Camera from being able to scroll. The bounds can be positioned where-ever you wish. By default they are from 0x0 to the canvas width x height. This means that the coordinate 0x0 is the top left of the Camera bounds. However, you can position them anywhere. So if you wanted a game world that was 2048x2048 in size, with 0x0 being the center of it, you can set the bounds x/y to be -1024, -1024, with a width and height of 2048. Depending on your game you may find it easier for 0x0 to be the top-left of the bounds, or you may wish 0x0 to be the middle.

Parameters:
Name Type Argument Default Description
x integer

The top-left x coordinate of the bounds.

y integer

The top-left y coordinate of the bounds.

width integer

The width of the bounds, in pixels.

height integer

The height of the bounds, in pixels.

centerOn boolean <optional>
false

If true the Camera will automatically be centered on the new bounds.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1105)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setDeadzone( [width] [, height])

Sets the Camera dead zone.

The deadzone is only used when the camera is following a target.

It defines a rectangular region within which if the target is present, the camera will not scroll. If the target moves outside of this area, the camera will begin scrolling in order to follow it.

The deadzone rectangle is re-positioned every frame so that it is centered on the mid-point of the camera. This allows you to use the object for additional game related checks, such as testing if an object is within it or not via a Rectangle.contains call.

The lerp values that you can set for a follower target also apply when using a deadzone.

Calling this method with no arguments will reset an active deadzone.

Parameters:
Name Type Argument Description
width number <optional>

The width of the deadzone rectangle in pixels. If not specified the deadzone is removed.

height number <optional>

The height of the deadzone rectangle in pixels.

Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 428)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setFlip(x, y)

Sets the horizontal and vertical flipped state of this Game Object.

Parameters:
Name Type Description
x boolean

The horizontal flipped state. false for no flip, or true to be flipped.

y boolean

The horizontal flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 105)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

setFlipX(value)

Sets the horizontal flipped state of this Game Object.

Parameters:
Name Type Description
value boolean

The flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 71)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

setFlipY(value)

Sets the vertical flipped state of this Game Object.

Parameters:
Name Type Description
value boolean

The flipped state. false for no flip, or true to be flipped.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 88)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

setFollowOffset( [x] [, y])

Sets the horizontal and vertical offset of the camera from its follow target. The values are subtracted from the targets position during the Cameras update step.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The horizontal offset from the camera follow target.x position.

y number <optional>
0

The vertical offset from the camera follow target.y position.

Since: 3.9.0
Source: src/cameras/2d/Camera.js (Line 814)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setLerp( [x] [, y])

Sets the linear interpolation value to use when following a target.

The default values of 1 means the camera will instantly snap to the target coordinates. A lower value, such as 0.1 means the camera will more slowly track the target, giving a smooth transition. You can set the horizontal and vertical values independently, and also adjust this value in real-time during your game.

Be sure to keep the value between 0 and 1. A value of zero will disable tracking on that axis.

Parameters:
Name Type Argument Default Description
x number <optional>
1

The amount added to the horizontal linear interpolation of the follow target.

y number <optional>
1

The amount added to the vertical linear interpolation of the follow target.

Since: 3.9.0
Source: src/cameras/2d/Camera.js (Line 786)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setMask(mask [, fixedPosition])

Sets the mask to be applied to this Camera during rendering.

The mask must have been previously created and can be either a GeometryMask or a BitmapMask.

Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.

If a mask is already set on this Camera it will be immediately replaced.

Masks have no impact on physics or input detection. They are purely a rendering component that allows you to limit what is visible during the render pass.

Note: You cannot mask a Camera that has renderToTexture set.

Parameters:
Name Type Argument Default Description
mask Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask

The mask this Camera will use when rendering.

fixedPosition boolean <optional>
true

Should the mask translate along with the Camera, or be fixed in place and not impacted by the Cameras transform?

Since: 3.17.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1418)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setName( [value])

Sets the name of this Camera. This value is for your own use and isn't used internally.

Parameters:
Name Type Argument Default Description
value string <optional>
''

The name of the Camera.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1182)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setOrigin( [x] [, y])

Sets the rotation origin of this Camera.

The values are given in the range 0 to 1 and are only used when calculating Camera rotation.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens. A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

Parameters:
Name Type Argument Default Description
x number <optional>
0.5

The horizontal origin value.

y number <optional>
x

The vertical origin value. If not defined it will be set to the value of x.

Since: 3.11.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 541)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setPipeline( [pipeline])

Sets the WebGL pipeline this Camera is using when rendering to a texture.

You can pass either the string-based name of the pipeline, or a reference to the pipeline itself.

Call this method with no arguments to clear any previously set pipeline.

Parameters:
Name Type Argument Description
pipeline string | Phaser.Renderer.WebGL.WebGLPipeline <optional>

The WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference. Or if left empty it will clear the pipeline.

Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 345)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setPosition(x [, y])

Set the position of the Camera viewport within the game.

This does not change where the camera is 'looking'. See setScroll to control that.

Parameters:
Name Type Argument Default Description
x number

The top-left x coordinate of the Camera viewport.

y number <optional>
x

The top-left y coordinate of the Camera viewport.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1202)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setRenderToTexture( [pipeline])

Sets the Camera to render to a texture instead of to the main canvas.

The Camera will redirect all Game Objects it's asked to render to this texture.

During the render sequence, the texture itself will then be rendered to the main canvas.

Doing this gives you the ability to modify the texture before this happens, allowing for special effects such as Camera specific shaders, or post-processing on the texture.

If running under Canvas the Camera will render to its canvas property.

If running under WebGL the Camera will create a frame buffer, which is stored in its framebuffer and glTexture properties.

If you set a camera to render to a texture then it will emit 2 events during the render loop:

First, it will emit the event prerender. This happens right before any Game Object's are drawn to the Camera texture.

Then, it will emit the event postrender. This happens after all Game Object's have been drawn, but right before the Camera texture is rendered to the main game canvas. It's the final point at which you can manipulate the texture before it appears in-game.

You should not enable this unless you plan on actually using the texture it creates somehow, otherwise you're just doubling the work required to render your game.

To temporarily disable rendering to a texture, toggle the renderToTexture boolean.

If you no longer require the Camera to render to a texture, call the clearRenderToTexture method, which will delete the respective textures and free-up resources.

Parameters:
Name Type Argument Description
pipeline string | Phaser.Renderer.WebGL.WebGLPipeline <optional>

An optional WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference.

Since: 3.13.0
Source: src/cameras/2d/Camera.js (Line 282)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setRotation( [value])

Set the rotation of this Camera. This causes everything it renders to appear rotated.

Rotating a camera does not rotate the viewport itself, it is applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The rotation of the Camera, in radians.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1225)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setRoundPixels(value)

Should the Camera round pixel values to whole integers when rendering Game Objects?

In some types of game, especially with pixel art, this is required to prevent sub-pixel aliasing.

Parameters:
Name Type Description
value boolean

true to round Camera pixels, false to not.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1246)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setScene(scene)

Sets the Scene the Camera is bound to.

Also populates the resolution property and updates the internal size values.

Parameters:
Name Type Description
scene Phaser.Scene

The Scene the camera is bound to.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1265)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setScroll(x [, y])

Set the position of where the Camera is looking within the game. You can also modify the properties Camera.scrollX and Camera.scrollY directly. Use this method, or the scroll properties, to move your camera around the game world.

This does not change where the camera viewport is placed. See setPosition to control that.

Parameters:
Name Type Argument Default Description
x number

The x coordinate of the Camera in the game world.

y number <optional>
x

The y coordinate of the Camera in the game world.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1306)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setSize(width [, height])

Set the size of the Camera viewport.

By default a Camera is the same size as the game, but can be made smaller via this method, allowing you to create mini-cam style effects by creating and positioning a smaller Camera viewport within your game.

Parameters:
Name Type Argument Default Description
width integer

The width of the Camera viewport.

height integer <optional>
width

The height of the Camera viewport.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1331)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setTint( [topLeft] [, topRight] [, bottomLeft] [, bottomRight])

Sets an additive tint on this Game Object.

The tint works by taking the pixel color values from the Game Objects texture, and then multiplying it by the color value of the tint. You can provide either one color value, in which case the whole Game Object will be tinted in that color. Or you can provide a color per corner. The colors are blended together across the extent of the Game Object.

To modify the tint color once set, either call this method again with new values or use the tint property to set all colors at once. Or, use the properties tintTopLeft, tintTopRight,tintBottomLeftandtintBottomRight` to set the corner color values independently.

To remove a tint call clearTint.

To swap this from being an additive tint to a fill based tint set the property tintFill to true.

Parameters:
Name Type Argument Default Description
topLeft integer <optional>
0xffffff

The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object.

topRight integer <optional>

The tint being applied to the top-right of the Game Object.

bottomLeft integer <optional>

The tint being applied to the bottom-left of the Game Object.

bottomRight integer <optional>

The tint being applied to the bottom-right of the Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 114)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

setTintFill( [topLeft] [, topRight] [, bottomLeft] [, bottomRight])

Sets a fill-based tint on this Game Object.

Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture with those in the tint. You can use this for effects such as making a player flash 'white' if hit by something. You can provide either one color value, in which case the whole Game Object will be rendered in that color. Or you can provide a color per corner. The colors are blended together across the extent of the Game Object.

To modify the tint color once set, either call this method again with new values or use the tint property to set all colors at once. Or, use the properties tintTopLeft, tintTopRight,tintBottomLeftandtintBottomRight` to set the corner color values independently.

To remove a tint call clearTint.

To swap this from being a fill-tint to an additive tint set the property tintFill to false.

Parameters:
Name Type Argument Default Description
topLeft integer <optional>
0xffffff

The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object.

topRight integer <optional>

The tint being applied to the top-right of the Game Object.

bottomLeft integer <optional>

The tint being applied to the bottom-left of the Game Object.

bottomRight integer <optional>

The tint being applied to the bottom-right of the Game Object.

Since: 3.11.0
Inherited From:
Source: src/gameobjects/components/Tint.js (Line 164)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

setViewport(x, y, width [, height])

This method sets the position and size of the Camera viewport in a single call.

If you're trying to change where the Camera is looking at in your game, then see the method Camera.setScroll instead. This method is for changing the viewport itself, not what the camera can see.

By default a Camera is the same size as the game, but can be made smaller via this method, allowing you to create mini-cam style effects by creating and positioning a smaller Camera viewport within your game.

Parameters:
Name Type Argument Default Description
x number

The top-left x coordinate of the Camera viewport.

y number

The top-left y coordinate of the Camera viewport.

width integer

The width of the Camera viewport.

height integer <optional>
width

The height of the Camera viewport.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1356)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setVisible(value)

Sets the visibility of this Camera.

An invisible Camera will skip rendering and input tests of everything it can see.

Parameters:
Name Type Description
value boolean

The visible state of the Camera.

Since: 3.10.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1475)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

setZoom( [value])

Set the zoom value of the Camera.

Changing to a smaller value, such as 0.5, will cause the camera to 'zoom out'. Changing to a larger value, such as 2, will cause the camera to 'zoom in'.

A value of 1 means 'no zoom' and is the default.

Changing the zoom does not impact the Camera viewport in any way, it is only applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
1

The zoom value of the Camera. The minimum it can be is 0.001.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1387)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

shake( [duration] [, intensity] [, force] [, callback] [, context])

Shakes the Camera by the given intensity over the duration specified.

Parameters:
Name Type Argument Default Description
duration integer <optional>
100

The duration of the effect in milliseconds.

intensity number <optional>
0.05

The intensity of the shake.

force boolean <optional>
false

Force the shake effect to start immediately, even if already running.

callback function <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 609)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)

startFollow(target [, roundPixels] [, lerpX] [, lerpY] [, offsetX] [, offsetY])

Sets the Camera to follow a Game Object.

When enabled the Camera will automatically adjust its scroll position to keep the target Game Object in its center.

You can set the linear interpolation value used in the follow code. Use low lerp values (such as 0.1) to automatically smooth the camera motion.

If you find you're getting a slight "jitter" effect when following an object it's probably to do with sub-pixel rendering of the targets position. This can be rounded by setting the roundPixels argument to true to force full pixel rounding rendering. Note that this can still be broken if you have specified a non-integer zoom value on the camera. So be sure to keep the camera zoom to integers.

Parameters:
Name Type Argument Default Description
target Phaser.GameObjects.GameObject | object

The target for the Camera to follow.

roundPixels boolean <optional>
false

Round the camera position to whole integers to avoid sub-pixel rendering?

lerpX number <optional>
1

A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track.

lerpY number <optional>
1

A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track.

offsetX number <optional>
0

The horizontal offset from the camera follow target.x position.

offsetY number <optional>
0

The vertical offset from the camera follow target.y position.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 836)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

stopFollow()

Stops a Camera from following a Game Object, if previously set via Camera.startFollow.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 901)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera

toggleFlipX()

Toggles the horizontal flipped state of this Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 41)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

toggleFlipY()

Toggles the vertical flipped state of this Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Flip.js (Line 56)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.Camera

toJSON()

Returns an Object suitable for JSON storage containing all of the Camera viewport and rendering properties.

Since: 3.0.0
Inherited From:
Source: src/cameras/2d/BaseCamera.js (Line 1488)
Returns:

A well-formed object suitable for conversion to JSON.

Type
Phaser.Types.Cameras.Scene2D.JSONCamera

<protected> update(time, delta)

Internal method called automatically by the Camera Manager.

Parameters:
Name Type Description
time integer

The current timestamp as generated by the Request Animation Frame or SetTimeout.

delta number

The delta time, in ms, elapsed since the last frame.

Since: 3.0.0
Overrides:
Source: src/cameras/2d/Camera.js (Line 935)

zoomTo(zoom [, duration] [, ease] [, force] [, callback] [, context])

This effect will zoom the Camera to the given scale, over the duration and with the ease specified.

Parameters:
Name Type Argument Default Description
zoom number

The target Camera zoom value.

duration integer <optional>
1000

The duration of the effect in milliseconds.

ease string | function <optional>
'Linear'

The ease to use for the pan. Can be any of the Phaser Easing constants or a custom function.

force boolean <optional>
false

Force the pan effect to start immediately, even if already running.

callback Phaser.Types.Cameras.Scene2D.CameraPanCallback <optional>

This callback will be invoked every frame for the duration of the effect. It is sent four arguments: A reference to the camera, a progress amount between 0 and 1 indicating how complete the effect is, the current camera scroll x coordinate and the current camera scroll y coordinate.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Since: 3.11.0
Source: src/cameras/2d/Camera.js (Line 657)
Fires:
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.Camera