API Docs for: v0.1.0
Show:

Camera Class

Extends Container

A basic Camera object that provides some effects. It also will contain the GUI to ensure they are using "screen-coords".

Constructor

Camera

(
  • state
)

Parameters:

  • state State

    The game state this camera belongs to

Methods

_fxCallback

(
  • fx
  • type
  • [callback]
)
private

The base callback for camera FX. This is called at the end of each aniamtion to free the FX class back into the pool.

Parameters:

  • fx Mixed

    The FX instance to free

  • type String

    The name of the instance type

  • [callback] Function optional

    The user callback to call.

_outsideBounds

(
  • x
  • y
)
Boolean private

Checks if a point is outside the bounds of the camera constraints.

Parameters:

  • x Number

    The new X position to test

  • y Number

    The new Y position to test

Returns:

Boolean:

true if the camera will move outside bounds to go to this point

addChild

(
  • child
)
Container | Sprite

Adds a child to the container and returns the child

Parameters:

Returns:

Container | Sprite:

The child that was added

addChildAt

(
  • child
  • index
)
Container | Sprite

Adds a child to the object at a specified index. If the index is out of bounds an error will be thrown

Parameters:

Returns:

Container | Sprite:

The child that was added

bringChildToTop

(
  • child
)
Container | Sprite

Brings a child to the top of the Z pile.

Parameters:

Returns:

Container | Sprite:

The child that was added

close

(
  • [shape='circle']
  • [duration=1000]
  • [position]
  • [callback]
)
fx.camera.Close

Performs a "close" animation that will cover the screen with a color.

Parameters:

  • [shape='circle'] String optional

    The shape to close with, can be either 'ellipse', 'circle', or 'rectangle'

  • [duration=1000] Number optional

    Number of milliseconds for the animation to complete

  • [position] Vector optional

    The position for the animation to close in on, defaults to camera center

  • [callback] Function optional

    A callback to call once the animation completes.

Returns:

fx.camera.Close:

The close effect that was created.

constrain

(
  • shape
)
Camera chainable

Sets the bounds the camera is allowed to go. Usually this is the world's size unless you set it manually.

Parameters:

Returns:

Camera:

Returns itself.

destroy

()

Destroys this object.

destroyAllChildren

() Container chainable

Destroys all the children of the object.

Returns:

Container:

Returns itself.

disablePhysics

() Mixed chainable async

Inherited from PhysicsTarget but overwritten in src\physics\PhysicsTarget.js:83

Disbales physics for this sprite

Returns:

Mixed:

Returns itself.

emit

(
  • type
  • data
)
Mixed chainable

Emits an event which will run all registered listeners for the event type

Parameters:

  • type String

    The event name to emit

  • data Mixed

    Any data you want passed along with the event

Returns:

Mixed:

Returns itself.

enablePhysics

(
  • system
)
Mixed chainable async

Enables physics for this sprite

Parameters:

Returns:

Mixed:

Returns itself.

fade

(
  • [color=0xFFFFFF]
  • [duration=1000]
  • [alpha=1]
  • [callback]
)
fx.camera.Fade

Fade the screen into a color. This will fade into a color that will eventually cover the screen.

Parameters:

  • [color=0xFFFFFF] Number optional

    The color to fade into

  • [duration=1000] Number optional

    The time it should take (in milliseconds) to fade in

  • [alpha=1] Number optional

    The opacity to fade into (final opacity)

  • [callback] Function optional

    A callback to call once the animation completes.

Returns:

fx.camera.Fade:

The close effect that was created.

flash

(
  • [color=0xFFFFFF]
  • [duration=1000]
  • [alpha=1]
  • [callback]
)
fx.camera.Flash

Flash the screen with a color. This will cover the screen in a color then fade it out.

Parameters:

  • [color=0xFFFFFF] Number optional

    The color to flash the screen with

  • [duration=1000] Number optional

    The time it should take (in milliseconds) to fade out

  • [alpha=1] Number optional

    The opacity of the initial flash of color (start opacity)

  • [callback] Function optional

    A callback to call once the animation completes.

Returns:

fx.camera.Flash:

The close effect that was created.

focus

(
  • x
  • y
)
Camera chainable

Focuses the camera on an x,y position. Ensures that the camera does not go outside the bounds set with setBounds()

Parameters:

  • x Number | Vector

    The x coord to focus on, if a Vector is passed the y param is ignored

  • y Number

    The y coord to focus on

Returns:

Camera:

Returns itself.

focusSprite

(
  • sprite
)
Camera chainable

Focuses the camera on a sprite.

Parameters:

  • sprite Sprite

    The sprite to focus on

Returns:

Camera:

Returns itself.

follow

(
  • sprite
  • [style=CAMERA_FOLLOW.LOCKON]
)
Camera chainable

Follows an sprite with the camera, ensuring they are always center view. You can pass a follow style to change the area an sprite can move around in before we start to move with them.

Parameters:

  • sprite Sprite

    The sprite to follow

  • [style=CAMERA_FOLLOW.LOCKON] CAMERA_FOLLOW optional

    The style of following

Returns:

Camera:

Returns itself.

hide

() Container chainable

Sets the container to visible = false

Returns:

Container:

Returns itself.

off

(
  • type
  • listener
)
Mixed chainable

Removes a listener function for an event type

Parameters:

  • type String

    The event name to emit

  • listener Function

    The function to remove

Returns:

Mixed:

Returns itself.

on

(
  • type
  • listener
)
Mixed chainable

Registers a listener function to be run on an event occurance

Parameters:

  • type String

    The event name to listen for

  • listener Function

    The function to execute when the event happens

Returns:

Mixed:

Returns itself.

once

(
  • type
  • listener
)
Mixed chainable

Registers a one-time callback for an event

Parameters:

  • type String

    The event name to listen for

  • listener Function

    the callback to call when the event occurs

Returns:

Mixed:

Returns itself.

onCollide

(
  • obj
  • collision
)
Boolean

Called whenever a collision occurs

Parameters:

  • obj Sprite | Container

    The sprite that you collide with

  • collision Collision

    Collision data object that contains information about the intersection

Returns:

Boolean:

If you return false explicitly the engine will not solve the collision. In this way you can make thing "not collide" if you don't want their types to collide.

pan

(
  • x
  • y
)
Camera chainable

Pans the camera around by the x,y amount. Ensures that the camera does not go outside the bounds set with setBounds()

Parameters:

  • x Number | Vector

    The x amount to pan, if a Point is passed the y param is ignored

  • y Number

    The y ammount to pan

Returns:

Camera:

Returns itself.

removeAllChildren

() Container chainable

Removes all children from the object.

Returns:

Container:

Returns itself.

removeChild

(
  • child
)
Container | Sprite

Removes a child from the object.

Parameters:

Returns:

Container | Sprite:

The child that was added

resize

(
  • w
  • h
)
Camera private chainable

Resizes the viewing area, this is called internally by your game instance when you call mygame.resize(). DO NOT CALL THIS DIRECTLY

Parameters:

  • w Number

    The new width

  • h Number

    The new height

Returns:

Camera:

Returns itself.

scanlines - color, axis, spacing, thickness, alpha, cb

(
  • [color=0x000000]
  • [axis=gf.AXIS.HORIZONTAL]
  • [spacing=4]
  • [thickness=1]
  • [alpha=0.3]
  • [callback]
)
fx.camera.Scanlines

Adds arcade-style scanlines to the camera viewport.

Parameters:

  • [color=0x000000] Number optional

    The color for the scanlines to be

  • [axis=gf.AXIS.HORIZONTAL] gf.AXIS optional

    The axis to draw the lines on

  • [spacing=4] Number optional

    Number of pixels between each line

  • [thickness=1] Number optional

    Number of pixels thick each line is

  • [alpha=0.3] Number optional

    The opacity of the lines

  • [callback] Function optional

    A callback to call once the animation completes.

Returns:

fx.camera.Scanlines:

The close effect that was created.

setMass

(
  • mass
)
Mixed chainable

Sets the mass of this sprite

Parameters:

  • mass Number

    The new mass of the object

Returns:

Mixed:

Returns itself.

setPosition

(
  • x
  • y
)
Mixed chainable

Sets the position of this sprite

Parameters:

  • x Number
  • y Number

Returns:

Mixed:

Returns itself.

setRotation

(
  • rotation
)
Mixed chainable

Sets the rotation of this sprite

Parameters:

  • rotation Number

    The new rotation of the object in radians

Returns:

Mixed:

Returns itself.

setVelocity

(
  • velocity
)
Mixed chainable

Sets the velocity of this sprite

Parameters:

  • velocity Vector

    The new velocity of the object

Returns:

Mixed:

Returns itself.

shake

(
  • [intensity=0.01]
  • [duration=1000]
  • [direction=gf.AXIS.BOTH]
  • [callback]
)
fx.camera.Shake

Shakes the camera around a bit.

Parameters:

  • [intensity=0.01] Number optional

    The intensity of the shaking

  • [duration=1000] Number optional

    The amount of time the screen shakes for (in milliseconds)

  • [direction=gf.AXIS.BOTH] gf.AXIS optional

    The axis to shake on

  • [callback] Function optional

    A callback to call once the animation completes.

Returns:

fx.camera.Shake:

The close effect that was created.

show

() Container chainable

Sets the container to visible = true

Returns:

Container:

Returns itself.

unconstrain

() Camera chainable

Removes the constraints of the camera, to allow free movement around the world

Returns:

Camera:

Returns itself.

unfollow

() Camera chainable

Stops following any sprites

Returns:

Camera:

Returns itself.

update

(
  • dt
)
Camera private

Called internally every frame. Updates all effects and the follow

Parameters:

  • dt Number

    The delta time (in seconds) since the last update

Returns:

Camera:

Returns iteself for chainability

Properties

_deadzone

Rectangle private

When following a sprite this is the space within the camera that it can move around before the camera moves to track it.

_phys

Object private

The physics namespace that all physics properties go into. Those properties are:

  • system {PhysicsSystem} PhysicsSystem that this object is a part of.
  • active {Boolean} Whether or not this target is actively having physics simulated.

Default: {}

_target

Sprite private

The target that the camera will follow

_targetPos

Vector private

The target's last position, to cache if we should try to move the camera or not

add

ObjectFactory

An object factory for creating game objects

alpha

Number

The opacity of the object.

bounds

Rectangle private

The bounds of that the camera can move to

children

Array

[read-only] The of children of this object.

fxpools

Object private

The fxpools for doing camera effects

game

Game

The game instance this camera belongs to

gui

Container

The container that holds all the GUI items, direct children of Camera are effects

hitArea

Rectangle | Polygon | Circle | Ellipse

This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

hSize

Vector

Half of the size of the camera

inertia

Number

The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)

Default: 0

interactive

Boolean

Wether or not the object will handle mouse events

Default: false

mass

Number

The mass of this object, please use setMass to set this value

Default: 0

parent

DisplayObject

[read-only] The display object that contains this display object.

position

Point

The coordinate of the object relative to the local coordinates of the parent.

rotation

Number

The rotation of the object in radians.

scale

Point

The scale factor of the object.

size

Vector

The size of the camera

stage

Stage

[read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

state

State

The game state this camera belongs to

visible

Boolean

The visibility of the object.

world

World

The world instance this camera is tied to

Events

click

A callback that is used when the users clicks on the displayObject with their mouse

Event Payload:

  • interactionData InteractionData

collision

On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • vec Vector

    Collision vector (for sensors this is normalized)

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision

mousedown

A callback that is used when the user clicks the mouse down over the displayObject

Event Payload:

  • interactionData InteractionData

mousemove

A callback that is used when the user moves the mouse while over the displayObject

Event Payload:

  • interactionData InteractionData

mouseout

A callback that is used when the users mouse leaves the displayObject

Event Payload:

  • interactionData InteractionData

mouseover

A callback that is used when the users mouse rolls over the displayObject

Event Payload:

  • interactionData InteractionData

mouseup

A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

Event Payload:

  • interactionData InteractionData

mouseupoutside

A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

Event Payload:

  • interactionData InteractionData

separate

On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision

tap

A callback that is used when the users taps on the displayObject with their finger basically a touch version of click

Event Payload:

  • interactionData InteractionData

touchend

A callback that is used when the user releases a touch over the displayObject

Event Payload:

  • interactionData InteractionData

touchendoutside

A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the displayObject

Event Payload:

  • interactionData InteractionData

touchstart

A callback that is used when the user touch's over the displayObject

Event Payload:

  • interactionData InteractionData