Class: Camera2d

me. Camera2d

new Camera2d(minX, minY, maxX, maxY)

a 2D orthographic camera
Parameters:
Name Type Description
minX Number start x offset
minY Number start y offset
maxX Number end x offset
maxY Number end y offset
Source:
camera2d.js, line 25

Extends

Members

<static> AXIS :Number

Axis definition
Type:
  • Number
Properties:
Name Type Description
NONE
HORIZONTAL
VERTICAL
BOTH
Source:
camera2d.js, line 31

<static> bounds :me.Rect

Camera bounds
Type:
Source:
camera2d.js, line 50

<static> damping :Number

Camera damping for smooth transition [0 .. 1]. 1 being the maximum value and will snap the camera to the target position
Type:
  • Number
Default Value:
  • 1.0
Source:
camera2d.js, line 70

alpha :Number

Define the renderable opacity
Set to zero if you do not wish an object to be drawn
Type:
  • Number
Inherited From:
Default Value:
  • 1.0
Source:
renderable.js, line 209
See:
  • me.Renderable#setOpacity
  • me.Renderable#getOpacity

ancestor :me.Container|me.Entity

a reference to the parent object that contains this renderable, or undefined if it has not been added to one.
Type:
Inherited From:
Default Value:
  • undefined
Source:
renderable.js, line 221

Methods

<static> fadeIn(color, duration, onComplete)

fadeIn effect

fade to the specified color

Parameters:
Name Type Argument Default Description
color me.Color | String a CSS color value
duration Number <optional>
1000 expressed in milliseconds
onComplete function <optional>
callback once effect is over
Source:
camera2d.js, line 491
Example
// flash the camera to white for 75ms
me.game.viewport.fadeIn("#FFFFFF", 75);

<static> fadeOut(color, duration, onComplete)

fadeOut(flash) effect

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

Parameters:
Name Type Argument Default Description
color me.Color | String a CSS color value
duration Number <optional>
1000 expressed in milliseconds
onComplete function <optional>
callback once effect is over
Source:
camera2d.js, line 465
Example
// 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.levelDirector.reloadLevel();
    me.game.viewport.fadeOut("#fff", 150);
});

<static> focusOn()

set the camera position around the specified object
Parameters:
Type Description
me.Renderable
Source:
camera2d.js, line 537

<static> follow(target, axis, damping)

set the camera to follow the specified renderable.
(this will put the camera center around the given target)
Parameters:
Name Type Argument Default Description
target me.Renderable | me.Vector2d renderable or position vector to follow
axis me.Camera2d.AXIS <optional>
this.AXIS.BOTH Which axis to follow
damping Number <optional>
1 default damping value
Source:
camera2d.js, line 264
Example
// 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);

<static> getHeight() → {Number}

return the camera height
Source:
camera2d.js, line 526
Returns:
Type
Number

<static> getWidth() → {Number}

return the camera width
Source:
camera2d.js, line 515
Returns:
Type
Number

<static> isVisible(rect) → {Boolean}

check if the specified rectangle is in the camera
Parameters:
Name Type Description
rect me.Rect
Source:
camera2d.js, line 552
Returns:
Type
Boolean

<static> localToWorld(x, y, v) → {me.Vector2d}

convert the given "local" (screen) coordinates into world coordinates
Parameters:
Name Type Argument Description
x Number
y Number
v Number <optional>
an optional vector object where to set the converted value
Source:
camera2d.js, line 564
Returns:
Type
me.Vector2d

<static> move(x, y)

move the camera upper-left position by the specified offset.
Parameters:
Name Type Description
x Number
y Number
Source:
camera2d.js, line 317
See:
Example
// Move the camera up by four pixels
me.game.viewport.move(0, -4);

<static> moveTo(x, y)

move the camera upper-left position to the specified coordinates
Parameters:
Name Type Description
x Number
y Number
Source:
camera2d.js, line 333
See:

<static> reset(x, y)

reset the camera position to specified coordinates
Parameters:
Name Type Argument Default Description
x Number <optional>
0
y Number <optional>
0
Source:
camera2d.js, line 154

<static> resize(w, h) → {me.Camera2d}

resize the camera
Parameters:
Name Type Description
w Number new width of the camera
h Number new height of the camera
Source:
camera2d.js, line 210
Returns:
this camera
Type
me.Camera2d

<static> setBounds(x, y, w, h)

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
Source:
camera2d.js, line 244

<static> setDeadzone(w, h)

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
Source:
camera2d.js, line 178
See:

<static> shake(intensity, duration, axis, onComplete, force)

shake the camera
Parameters:
Name Type Argument Default Description
intensity Number maximum offset that the screen can be moved while shaking
duration Number expressed in milliseconds
axis me.Camera2d.AXIS <optional>
this.AXIS.BOTH specify on which axis you want the shake effect
onComplete function <optional>
callback once shaking effect is over
force Boolean <optional>
if true this will override the current effect
Source:
camera2d.js, line 440
Example
// shake it baby !
me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH);

<static> unfollow()

unfollow the current target
Source:
camera2d.js, line 306

<static> worldToLocal(x, y, v) → {me.Vector2d}

convert the given world coordinates into "local" (screen) coordinates
Parameters:
Name Type Argument Description
x Number
y Number
v Number <optional>
an optional vector object where to set the converted value
Source:
camera2d.js, line 585
Returns:
Type
me.Vector2d