me.Camera2d(minX, minY, maxX, maxY)

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

Extends

Members

static AXIS :Number

Axis definition

Properties:
Name Type Description
NONE
HORIZONTAL
VERTICAL
BOTH

static bounds :me.Rect

Camera bounds

static damping :Number

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

Default Value:
  • 1.0

alpha :Number

Define the renderable opacity
Set to zero if you do not wish an object to be drawn

Inherited From:
Default Value:
  • 1.0
See:
  • me.Renderable#setOpacity
  • me.Renderable#getOpacity

ancestor :me.Container|me.Entity

a reference to the parent object that contains this renderable

Inherited From:
Default Value:
  • undefined

Methods

static fadeIn(color, durationopt, onCompleteopt)

fadeIn effect

fade to the specified color

Parameters:
Name Type Attributes 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

Example
// flash the camera to white for 75ms
me.game.viewport.fadeIn("#FFFFFF", 75);

static fadeOut(color, durationopt, onCompleteopt)

fadeOut(flash) effect

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

Parameters:
Name Type Attributes 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

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

static follow(target, axisopt, dampingopt)

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

Parameters:
Name Type Attributes 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

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

Returns:
Number

static getWidth() → {Number}

return the camera width

Returns:
Number

static isVisible(object, floatingopt) → {Boolean}

check if the specified renderable is in the camera

Parameters:
Name Type Attributes Default Description
object me.Renderable
floating Boolean <optional>
==object.floating

if visibility check should be done against screen coordinates

Returns:
Boolean

static localToWorld(x, y, vopt) → {me.Vector2d}

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

Parameters:
Name Type Attributes Description
x Number
y Number
v Number <optional>

an optional vector object where to set the converted value

Returns:
me.Vector2d

static move(x, y)

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

Parameters:
Name Type Description
x Number
y Number
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
See:

static reset(xopt, yopt)

reset the camera position to specified coordinates

Parameters:
Name Type Attributes Default Description
x Number <optional>
0
y Number <optional>
0

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

Returns:
me.Camera2d -

this camera

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

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

See:

static shake(intensity, duration, axisopt, onCompleteopt, forceopt)

shake the camera

Parameters:
Name Type Attributes 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

Example
// shake it baby !
me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH);

static unfollow()

unfollow the current target

static worldToLocal(x, y, vopt) → {me.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:
me.Vector2d