Camera2d

class Camera2d extends Renderable

a 2D orthographic camera

Constructor


new Camera2d(minX: number, minY: number, maxX: number, maxY: number) → {}
Parameters:
Name Type Description
minX number

start x offset

minY number

start y offset

maxX number

end x offset

maxY number

end y offset

Summary


Properties from Camera2d

Properties inherited from Rect

number
bottom
number
centerX
number
centerY
number
height
number
left
number
right
number
top
string
type = "Rectangle"
number
width

Properties inherited from Polygon

Array<Vector2d>
points

Public Properties


bounds camera2d.js:54
bounds: Bounds

Bounds

Camera bounds

damping camera2d.js:70
damping: number = 1.0

number

Camera damping for smooth transition [0 .. 1]. 1 being the maximum value and will snap the camera to the target position

far camera2d.js:91
far: number = 1000

number

the furthest point relative to the camera.

near camera2d.js:81
near: number = -1000

number

the closest point relative to the camera

projectionMatrix camera2d.js:101
projectionMatrix: Matrix3d

Matrix3d

the default camera projection matrix (2d cameras use an orthographic projection by default).

Public Methods


fadeIn camera2d.js:550
fadeIn(color: Color | string, duration: number, onComplete: Function) → {}

fadeIn effect

fade to the specified color

// flash the camera to white for 75ms
me.game.viewport.fadeIn("#FFFFFF", 75);
Parameters:
Name Type Attributes Default Description
color Color | string

a CSS color value

duration number

<optional>

1000

expressed in milliseconds

onComplete Function

<optional>

callback once effect is over

fadeOut camera2d.js:525
fadeOut(color: Color | string, duration: number, onComplete: Function) → {}

fadeOut(flash) effect

screen is filled with the specified color and slowly goes back to normal

// fade the camera to white upon dying, reload the level, and then fade out back
me.game.viewport.fadeIn("#fff", 150, function() {
    me.audio.play("die", false);
    me.level.reload();
    me.game.viewport.fadeOut("#fff", 150);
});
Parameters:
Name Type Attributes Default Description
color Color | string

a CSS color value

duration number

<optional>

1000

expressed in milliseconds

onComplete Function

<optional>

callback once effect is over

focusOn camera2d.js:573
focusOn(target: Renderable | Entity | Sprite | NineSliceSprite) → {}

set the camera position around the specified object

Parameters:
Name Type Description
target Renderable | Entity | Sprite | NineSliceSprite

the renderable to focus the camera on

follow camera2d.js:311
follow(target: Renderable | Vector2d, axis: number, damping: number) → {}

set the camera to follow the specified renderable.
(this will put the camera center around the given target)

// set the camera to follow this renderable on both axis, and enable damping
me.game.viewport.follow(this, me.game.viewport.AXIS.BOTH, 0.1);
Parameters:
Name Type Attributes Default Description
target Renderable | Vector2d

renderable or position vector to follow

axis number

<optional>

me.game.viewport.AXIS.BOTH

Which axis to follow (see Camera2d.AXIS)

damping number

<optional>

1

default damping value

isVisible camera2d.js:587
isVisible(obj: Renderable | Entity | Sprite | NineSliceSprite, floating : boolean) → {boolean}

check if the specified renderable is in the camera

Parameters:
Name Type Attributes Default Description
obj Renderable | Entity | Sprite | NineSliceSprite

to be checked against

floating boolean

<optional>

obj.floating

if visibility check should be done against screen coordinates

Returns:
Type Description
boolean

true if within the viewport

localToWorld camera2d.js:605
localToWorld(x: number, y: number, v: number) → {Vector2d}

convert the given "local" (screen) coordinates into world coordinates

Parameters:
Name Type Attributes Description
x number

the x coordinate of the local point to be converted

y number

the y coordinate of the local point to be converted

v number

<optional>

an optional vector object where to set the converted value

Returns:
Type Description
Vector2d
move camera2d.js:363
move(x: number, y: number) → {}

move the camera upper-left position by the specified offset.

// Move the camera up by four pixels
me.game.viewport.move(0, -4);
Parameters:
Name Type Description
x number

horizontal offset

y number

vertical offset

See: Camera2d.focusOn
moveTo camera2d.js:378
moveTo(x: number, y: number) → {}

move the camera upper-left position to the specified coordinates

Parameters:
Name Type Description
x number
y number
See: Camera2d.focusOn
reset camera2d.js:206
reset(x: number, y: number) → {}

reset the camera position to specified coordinates

Parameters:
Name Type Attributes Default Description
x number

<optional>

0

initial position of the camera on the x axis

y number

<optional>

0

initial position of the camera on the y axis

resize camera2d.js:263
resize(w: number, h: number) → {Camera2d}

resize the camera

Parameters:
Name Type Description
w number

new width of the camera

h number

new height of the camera

Returns:
Type Description
Camera2d

this camera

setBounds camera2d.js:293
setBounds(x: number, y: number, w: number, h: number) → {}

set the camera boundaries (set to the world limit by default). the camera is bound to the given coordinates and cannot move/be scrolled outside of it.

Parameters:
Name Type Description
x number

world left limit

y number

world top limit

w number

world width limit

h number

world height limit

setDeadzone camera2d.js:233
setDeadzone(w: number, h: number) → {}

change the deadzone settings. the "deadzone" defines an area within the current camera in which the followed renderable can move without scrolling the camera.

Parameters:
Name Type Description
w number

deadzone width

h number

deadzone height

See: Camera2d.follow
shake camera2d.js:502
shake(intensity: number, duration: number, axis: number, onComplete: Function, force: boolean) → {}

shake the camera

// shake it baby !
me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH);
Parameters:
Name Type Attributes Default Description
intensity number

maximum offset that the screen can be moved while shaking

duration number

expressed in milliseconds

axis number

<optional>

me.game.viewport.AXIS.BOTH

specify on which axis to apply the shake effect (see Camera2d.AXIS)

onComplete Function

<optional>

callback once shaking effect is over

force boolean

<optional>

if true this will override the current effect

unfollow camera2d.js:353
unfollow() → {}

unfollow the current target

worldToLocal camera2d.js:624
worldToLocal(x: number, y: number, v: number) → {Vector2d}

convert the given world coordinates into "local" (screen) coordinates

Parameters:
Name Type Attributes Description
x number
y number
v number

<optional>

an optional vector object where to set the converted value

Returns:
Type Description
Vector2d

a vector with the converted local coordinates


Powered by webdoc!