new Camera(game, id, x, y, width, height)
A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | Game reference to the currently running game. |
id |
number | Not being used at the moment, will be when Phaser supports multiple camera |
x |
number | Position of the camera on the X axis |
y |
number | Position of the camera on the Y axis |
width |
number | The width of the view rectangle |
height |
number | The height of the view rectangle |
- Source:
Members
-
<static, constant> FOLLOW_LOCKON :number
-
Type:
- number
- Source:
-
<static, constant> FOLLOW_PLATFORMER :number
-
Type:
- number
- Source:
-
<static, constant> FOLLOW_TOPDOWN :number
-
Type:
- number
- Source:
-
<static, constant> FOLLOW_TOPDOWN_TIGHT :number
-
Type:
- number
- Source:
-
atLimit
-
- Source:
Properties:
Name Type Description atLimitboolean Whether this camera is flush with the World Bounds or not.
-
bounds
-
The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World. The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the center of the world.
- Source:
Properties:
Name Type Description boundsPhaser.Rectangle The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere.
-
deadzone
-
- Source:
Properties:
Name Type Description deadzonePhaser.Rectangle Moving inside this Rectangle will not cause the camera to move.
-
displayObject
-
- Source:
Properties:
Name Type Description displayObjectPIXI.DisplayObject The display object to which all game objects are added. Set by World.boot
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game A reference to the currently running Game.
-
height
-
The Cameras height. By default this is the same as the Game size and should not be adjusted for now.
- Source:
Properties:
Name Type Description heightnumber Gets or sets the cameras height.
-
id
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description idnumber Reserved for future multiple camera set-ups.
-
position
-
The Cameras position. This value is automatically clamped if it falls outside of the World bounds.
- Source:
Properties:
Name Type Description positionPhaser.Point Gets or sets the cameras xy position using Phaser.Point object.
-
roundPx
-
- Default Value:
- true
- Source:
Properties:
Name Type Description roundPxboolean If a Camera has roundPx set to
trueit will callview.flooras part of its update loop, keeping its boundary to integer values. Set this tofalseto disable this from happening. -
scale
-
- Source:
Properties:
Name Type Description scalePhaser.Point The scale of the display object to which all game objects are added. Set by World.boot
-
screenView
-
- Source:
Properties:
Name Type Description screenViewPhaser.Rectangle Used by Sprites to work out Camera culling.
-
target
-
- Default Value:
- null
- Source:
Properties:
Name Type Description targetPhaser.Sprite If the camera is tracking a Sprite, this is a reference to it, otherwise null.
-
view
-
Camera view. The view into the world we wish to render (by default the game dimensions). The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render. Objects outside of this view are not rendered if set to camera cull.
- Source:
Properties:
Name Type Description viewPhaser.Rectangle -
visible
-
- Default Value:
- true
- Source:
Properties:
Name Type Description visibleboolean Whether this camera is visible or not.
-
width
-
The Cameras width. By default this is the same as the Game size and should not be adjusted for now.
- Source:
Properties:
Name Type Description widthnumber Gets or sets the cameras width.
-
world
-
- Source:
Properties:
Name Type Description worldPhaser.World A reference to the game world.
-
x
-
The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds.
- Source:
Properties:
Name Type Description xnumber Gets or sets the cameras x position.
-
y
-
The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds.
- Source:
Properties:
Name Type Description ynumber Gets or sets the cameras y position.
Methods
-
checkWorldBounds()
-
Method called to ensure the camera doesn't venture outside of the game world.
- Source:
-
focusOn(displayObject)
-
Move the camera focus on a display object instantly.
Parameters:
Name Type Description displayObjectany The display object to focus the camera on. Must have visible x/y properties.
- Source:
-
focusOnXY(x, y)
-
Move the camera focus on a location instantly.
Parameters:
Name Type Description xnumber X position.
ynumber Y position.
- Source:
-
follow(target, style)
-
Tells this camera which sprite to follow.
Parameters:
Name Type Argument Description targetPhaser.Sprite | Phaser.Image | Phaser.Text The object you want the camera to track. Set to null to not follow anything.
stylenumber <optional>
Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
- Source:
-
reset()
-
Resets the camera back to 0,0 and un-follows any object it may have been tracking.
- Source:
-
setBoundsToWorld()
-
Update the Camera bounds to match the game world.
- Source:
-
setPosition(x, y)
-
A helper function to set both the X and Y properties of the camera at once without having to use game.camera.x and game.camera.y.
Parameters:
Name Type Description xnumber X position.
ynumber Y position.
- Source:
-
setSize(width, height)
-
Sets the size of the view rectangle given the width and height in parameters.
Parameters:
Name Type Description widthnumber The desired width.
heightnumber The desired height.
- Source:
-
unfollow()
-
Sets the Camera follow target to null, stopping it from following an object if it's doing so.
- Source:
-
update()
-
Update focusing and scrolling.
- Source: