API Documentation for: 0.11.8
Show:

platypus.components.Camera Class

This component controls the game camera deciding where and how it should move. The camera also broadcasts messages when the window resizes or its orientation changes.

Methods

'child-entity-added'

(
  • entity
)

The viewport is flagged to update when children are added.

Parameters:

'child-entity-updated'

(
  • entity
)

Defined in 'child-entity-updated':303

Available since 0.6.8

Triggers "camera-update" on newly changed entities.

Parameters:

  • entity platypus.Entity

    Expects an entity as the message object to determine whether to trigger camera-update on it.

'follow'

(
  • message
)

Defined in 'follow':540

On receiving this message, the camera begins following the requested object.

Parameters:

  • message Object
    • mode String

      Can be "locked", "forward", "bounding", "anchor-bound", or "static". "static" suspends following, but the other three settings require that the entity parameter be defined. Also set the bounding area parameters if sending "bounding" as the following method and the movement parameters if sending "forward" as the following method.

    • [entity] platypus.Entity optional

      The entity that the camera should commence following.

    • [top] Number optional

      The top of a bounding box following an entity.

    • [left] Number optional

      The left of a bounding box following an entity.

    • [width] Number optional

      The width of a bounding box following an entity.

    • [height] Number optional

      The height of a bounding box following an entity.

    • [movementX] Number optional

      Movement multiplier for focusing the camera ahead of a moving entity in the horizontal direction.

    • [movementY] Number optional

      Movement multiplier for focusing the camera ahead of a moving entity in the vertical direction.

    • [offsetX] Number optional

      How far to offset the camera from the entity horizontally.

    • [offsetY] Number optional

      How far to offset the camera from the entity vertically.

    • [time] Number optional

      How many milliseconds to follow the entity.

'load'

()

Defined in 'load':261

Sets up the camera window size on load.

'mousedown'

(
  • event
)

Defined in 'mousedown':343

Available since 0.9.0

If mouse dragging should cause the camera to move, this listens for the beginning of the drag motion.

Parameters:

  • event Object

    The mouse event.

'pressmove'

(
  • event
)

Defined in 'pressmove':367

Available since 0.9.0

If mouse dragging should cause the camera to move, this listens the drag motion.

Parameters:

  • event Object

    The mouse event.

'pressup'

(
  • event
)

Defined in 'pressup':384

Available since 0.9.0

If mouse dragging should cause the camera to move, this listens for the end of the drag motion.

Parameters:

  • event Object

    The mouse event.

'relocate'

(
  • location
)

Defined in 'relocate':507

The camera listens for this event to change its position in the world.

Parameters:

  • location Vector | Object

    List of key/value pairs describing new location

    • x Number

      New position along the x-axis.

    • y Number

      New position along the y-axis.

    • [time] Number optional

      The time to transition to the new location.

    • [ease] Function optional

      The ease function to use. Defaults to a linear transition.

'render-world'

(
  • data
)

Defined in 'render-world':270

On receiving this message, the camera begins viewing the world.

Parameters:

  • data Object

    Information about the world.

    • world PIXI.Container

      The container containing world entities.

'resize-camera'

(
  • dimensions
)

Defined in 'resize-camera':493

The camera listens for this event to change its world viewport size.

Parameters:

  • dimensions Object

    List of key/value pairs describing new viewport size

    • width Number

      Width of the camera viewport

    • height Number

      Height of the camera viewport

'shake'

(
  • shake
)

Defined in 'shake':561

On receiving this message, the camera will shake around its target location.

Parameters:

  • shake Object
    • [xMagnitude] Number optional

      How much to move along the x axis.

    • [yMagnitude] Number optional

      How much to move along the y axis.

    • [xFrequency] Number optional

      How quickly to shake along the x axis.

    • [yFrequency] Number optional

      How quickly to shake along the y axis.

    • [time] Number optional

      How long the camera should shake.

'tick'

(
  • message
)

Defined in 'tick':401

On a "tick" step event, the camera updates its location according to its current state.

Parameters:

  • message Object
    • delta Number

      If necessary, the current camera update function may require the length of the tick to adjust movement rate.

'world-loaded'

(
  • message
)

Defined in 'world-loaded':318

On receiving this message, the camera updates its world location and size as necessary. An example of this message is triggered by the TiledLoader component.

Parameters:

  • message Object
    • [width] Number optional

      The width of the loaded world.

    • [height] Number optional

      The height of the loaded world.

    • [camera] platypus.Entity optional

      An entity that the camera should follow in the loaded world.

addEventListener

(
  • event
  • callback
)
Function private
This method adds an event listener to the entity.

Parameters:

  • event String
    The event that this component should listen for.
  • callback Function
    The handler for the event.

Returns:

Function: handler A reference to the bound handler.

addMethod

(
  • name
  • func
)
private
This method adds a method to the entity.

Parameters:

  • name String
    The name of the method. For example, if name is "turnYellow", the method is accessible on the entity as entity.turnYellow().
  • func Function
    The function describing the method.

destroy

() private

Inherited from platypus.Component: destroy:54

This method cleans up listeners and methods that this component added to the entity. It should never be called by the component itself. Call this.owner.removeComponent(this) instead.

getAssetList

(
  • definition
  • properties
  • defaultProperties
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • definition Object
    The definition for the component.
  • properties Object
    The properties of the Entity.
  • defaultProperties Object
    The default properties of the Entity.

Returns:

Array: A list of the necessary assets to load.

getLateAssetList

(
  • data
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • data Object
    Scene data that affects the list of assets.

Returns:

Array: A list of the necessary assets to load.

isOnCanvas

(
  • bounds
)
Boolean

Defined in isOnCanvas:997

Available since 0.10.0

Returns whether a particular display object intersects the camera's viewport on the canvas.

Parameters:

  • bounds PIXI.Rectangle | Object

    The bounds of the display object.

    • height Number

      The height of the display object.

    • width Number

      The width of the display object.

    • x Number

      The left edge of the display object.

    • y Number

      The top edge of the display object.

Returns:

Boolean:

Whether the display object intersects the camera's bounds.

removeEventListener

(
  • event
  • callback
)
private
This method removes an event listener from the entity.

Parameters:

  • event String
    The event for which to remove a listener.
  • callback Function
    The listener to remove. If not supplied, all event listeners for the provided event are removed.

removeEventListeners

(
  • [listeners]
)
private
This method removes multiple event listeners from the entity.

Parameters:

  • [listeners] Array optional
    The list of listeners to remove. If not supplied, all event listeners are removed.

removeMethod

(
  • name
)
private
This method removes a method from the entity.

Parameters:

  • name String
    The name of the method to be removed.

toJSON

() Object

Inherited from platypus.Component: toJSON:45

Available since 0.11.0

Returns a JSON object describing the component.

Returns:

Object: Returns a JSON definition that can be used to recreate the component.

toString

() String
Returns a string describing the component.

Returns:

String: Returns the component type as a string of the form "[Component ComponentType]".

windowToWorld

(
  • windowVector
  • withOffset
  • vector
)
platypus.Vector

Defined in windowToWorld:1015

Returns a world coordinate corresponding to a provided window coordinate.

Parameters:

  • windowVector platypus.Vector

    A vector describing a window position.

  • withOffset Boolean

    Whether to provide a world position relative to the camera's location.

  • vector platypus.Vector

    If provided, this is used as the return vector.

Returns:

platypus.Vector:

A vector describing a world position.

worldToWindow

(
  • worldVector
  • withOffset
  • vector
)
platypus.Vector

Defined in worldToWindow:1038

Returns a window coordinate corresponding to a provided world coordinate.

Parameters:

  • worldVector platypus.Vector

    A vector describing a world position.

  • withOffset Boolean

    Whether to provide a window position relative to the camera's location.

  • vector platypus.Vector

    If provided, this is used as the return vector.

Returns:

platypus.Vector:

A vector describing a window position.

Properties

canvas

DOMElement Canvas

Defined in canvas:126

The entity's canvas element is used to determine the window size of the camera.

Default: null

height

Number

Defined in height:52

Number specifying height of viewport in world coordinates.

Default: 0

mode

String

Defined in mode:61

Available since 0.9.0

Specifies whether the camera should be draggable via the mouse by setting to 'pan'.

Default: 'static'

overflow

Boolean

Defined in overflow:71

Whether camera overflows to cover the whole canvas or remains contained within its aspect ratio's boundary.

Default: false

rotate

Boolean

Defined in rotate:98

Whether, when following an entity, the camera should rotate to match the entity's orientation.

Default: false

stretch

Boolean

Defined in stretch:80

Boolean value that determines whether the camera should stretch the world viewport when window is resized. Defaults to false which maintains the proper aspect ratio.

Default: : false

threshold

Number

Defined in threshold:89

Sets how many units the followed entity can move before the camera will re-center. This should be lowered for small-value coordinate systems such as Box2D.

Default: 1

transitionAngle

Number

Defined in transitionAngle:153

Sets how quickly the camera should rotate to a new orientation.

Default: : 600

transitionX

Number

Defined in transitionX:135

Sets how quickly the camera should pan to a new position in the horizontal direction.

Default: 400

transitionY

Number

Defined in transitionY:144

Sets how quickly the camera should pan to a new position in the vertical direction.

Default: 600

width

Number

Defined in width:43

Number specifying width of viewport in world coordinates.

Default: 0

x

Number

Defined in x:107

Number specifying the horizontal center of viewport in world coordinates.

Default: 0

y

Number

Defined in y:116

Number specifying the vertical center of viewport in world coordinates.

Default: 0

Events

'camera-loaded'

Defined in 'camera-loaded':292

On receiving a "world-loaded" message, the camera broadcasts the world size to all children in the world.

Event Payload:

'camera-update'

Defined in 'camera-update':460

This component fires "camera-update" when the position of the camera in the world has changed. This event is triggered on both the entity (typically a layer) as well as children of the entity.

Event Payload:

  • message Object
    • world platypus.AABB

      The dimensions of the world map.

    • orientation Number

      Number describing the orientation of the camera.

    • scaleX Number

      Number of window pixels that comprise a single world coordinate on the x-axis.

    • scaleY Number

      Number of window pixels that comprise a single world coordinate on the y-axis.

    • viewport platypus.AABB

      An AABB describing the world viewport area.

    • stationary Boolean

      Whether the camera is moving.