Camera2d
class Camera2d extends Renderable
a 2D orthographic camera
Constructor
new Camera2d(minX: number, minY: number, maxX: number, maxY: number) → {}
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
Bounds |
|
number |
|
number |
|
number |
|
Matrix3d |
|
Methods from Camera2d
|
|
|
|
|
|
|
|
boolean |
|
Vector2d |
|
|
|
|
|
|
|
Camera2d |
|
|
|
|
|
|
|
|
|
Vector2d |
|
Properties inherited from Renderable
number |
|
boolean |
|
Container | Entity |
|
ObservableVector2d |
|
boolean |
|
string |
|
Body |
|
Matrix2d |
|
number |
|
boolean |
|
string |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Rect | RoundRect | Polygon | Line | Ellipse |
|
string |
|
Function |
|
Application |
|
ObservableVector3d |
|
GLShader |
|
Color |
|
boolean |
|
Properties inherited from Rect
Methods inherited from Renderable
Methods inherited from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Public Properties
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
projectionMatrix: Matrix3d
Matrix3d
the default camera projection matrix (2d cameras use an orthographic projection by default).
Public Methods
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);
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(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);
});
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(target: Renderable | Entity | Sprite | NineSliceSprite) → {}
set the camera position around the specified object
Name | Type | Description |
---|---|---|
target | Renderable | Entity | Sprite | NineSliceSprite |
the renderable to focus the camera on |
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);
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(obj: Renderable | Entity | Sprite | NineSliceSprite, floating : boolean) → {boolean}
check if the specified renderable is in the camera
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 |
Type | Description |
---|---|
boolean |
true if within the viewport |
localToWorld(x: number, y: number, v: number) → {Vector2d}
convert the given "local" (screen) coordinates into world coordinates
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 |
Type | Description |
---|---|
Vector2d |
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);
Name | Type | Description |
---|---|---|
x | number |
horizontal offset |
y | number |
vertical offset |
moveTo(x: number, y: number) → {}
move the camera upper-left position to the specified coordinates
Name | Type | Description |
---|---|---|
x | number | |
y | number |
reset(x: number, y: number) → {}
reset the camera position to specified coordinates
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(w: number, h: number) → {Camera2d}
resize the camera
Name | Type | Description |
---|---|---|
w | number |
new width of the camera |
h | number |
new height of the camera |
Type | Description |
---|---|
Camera2d |
this camera |
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.
Name | Type | Description |
---|---|---|
x | number |
world left limit |
y | number |
world top limit |
w | number |
world width limit |
h | number |
world height limit |
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.
Name | Type | Description |
---|---|---|
w | number |
deadzone width |
h | number |
deadzone height |
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);
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 |
worldToLocal(x: number, y: number, v: number) → {Vector2d}
convert the given world coordinates into "local" (screen) coordinates
Name | Type | Attributes | Description |
---|---|---|---|
x | number | ||
y | number | ||
v | number |
<optional> |
an optional vector object where to set the converted value |
Type | Description |
---|---|
Vector2d |
a vector with the converted local coordinates |