Class: Camera

Phaser. Camera

Phaser.Camera

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

Properties:
Name Type Description
atLimit boolean

Whether this camera is flush with the World Bounds or not.

Source:

deadzone

Properties:
Name Type Description
deadzone Phaser.Rectangle

Moving inside this Rectangle will not cause camera moving.

Source:

game

Properties:
Name Type Description
game Phaser.Game

A reference to the currently running Game.

Source:

height

The Cameras height. By default this is the same as the Game size and should not be adjusted for now.

Properties:
Name Type Description
height number

Gets or sets the cameras height.

Source:

id

Properties:
Name Type Description
id number

Reserved for future multiple camera set-ups.

Default Value:
  • 0
Source:

screenView

Properties:
Name Type Description
screenView Phaser.Rectangle

Used by Sprites to work out Camera culling.

Source:

target

Properties:
Name Type Description
target Phaser.Sprite

If the camera is tracking a Sprite, this is a reference to it, otherwise null.

Default Value:
  • null
Source:

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 (unless set to ignore the Camera, i.e. UI?).

Properties:
Name Type Description
view Phaser.Rectangle
Source:

visible

Properties:
Name Type Description
visible boolean

Whether this camera is visible or not.

Default Value:
  • true
Source:

width

The Cameras width. By default this is the same as the Game size and should not be adjusted for now.

Properties:
Name Type Description
width number

Gets or sets the cameras width.

Source:

world

Properties:
Name Type Description
world Phaser.World

A reference to the game world.

Source:

x

The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds.

Properties:
Name Type Description
x number

Gets or sets the cameras x position.

Source:

y

The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds.

Properties:
Name Type Description
y number

Gets or sets the cameras y position.

Source:

Methods

checkWorldBounds()

Method called to ensure the camera doesn't venture outside of the game world.

Source:

focusOnXY(x, y)

Move the camera focus to a location instantly.

Parameters:
Name Type Description
x number

X position.

y number

Y position.

Source:

follow(target, style)

Tells this camera which sprite to follow.

Parameters:
Name Type Argument Description
target Phaser.Sprite

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

style number <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:

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
x number

X position.

y number

Y position.

Source:

setSize(width, height)

Sets the size of the view rectangle given the width and height in parameters.

Parameters:
Name Type Description
width number

The desired width.

height number

The desired height.

Source:

update()

Update focusing and scrolling.

Source:
Phaser Copyright © 2012-2013 Photon Storm Ltd.
Documentation generated by JSDoc 3.2.0-dev on Thu Oct 03 2013 02:35:45 GMT+0100 (BST) using the DocStrap template.