start x offset
start y offset
end x offset
end y offset
Define the renderable opacity
Set to zero if you do not wish an object to be drawn
Whether the renderable object will always update, even when outside of the viewport
a reference to the parent object that contains this renderable
The anchor point is used for attachment behavior, and/or when applying transformations.
The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner

a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.
Note: Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
To specify a value through Tiled, use a json expression like json:{"x":0.5,"y":0.5}.
Whether this camera should automatically resize when the canvas resizes. Set to false for non-default cameras with fixed dimensions (e.g. minimap, split-screen viewports).
When enabled, an object container will automatically apply any defined transformation before calling the child draw method.
// enable "automatic" transformation when the object is activated
onActivateEvent: function () {
// reset the transformation matrix
this.currentTransform.identity();
// ensure the anchor point is the renderable center
this.anchorPoint.set(0.5, 0.5);
// enable auto transform
this.autoTransform = true;
....
}
Axis definition NONE no axis HORIZONTAL horizontal axis only VERTICAL vertical axis only BOTH both axis
the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
the renderable physic body
// define a new Player Class
class PlayerEntity extends me.Sprite {
// constructor
constructor(x, y, settings) {
// call the parent constructor
super(x, y , settings);
// define a basic walking animation
this.addAnimation("walk", [...]);
// define a standing animation (using the first frame)
this.addAnimation("stand", [...]);
// set the standing animation as default
this.setCurrentAnimation("stand");
// add a physic body
this.body = new me.Body(this);
// add a default collision shape
this.body.addShape(new me.Rect(0, 0, this.width, this.height));
// configure max speed, friction, and initial force to be applied
this.body.setMaxVelocity(3, 15);
this.body.setFriction(0.4, 0);
this.body.force.set(3, 0);
this.isKinematic = false;
// set the display to follow our position on both axis
app.viewport.follow(this.pos, app.viewport.AXIS.BOTH);
}
...
}
Camera bounds
the renderable transformation matrix (4x4).
For standard 2D use, only the 2D components are used (rotate around Z, scale X/Y, translate X/Y).
For 3D use (e.g. Mesh), the full 4x4 matrix supports rotation around any axis,
3D translation, and perspective projection.
Use the rotate(), scale(), and translate() methods rather than modifying this directly.
Camera damping for smooth transition [0 .. 1]. 1 being the maximum value and will snap the camera to the target position
the camera deadzone
The edges here are the direction of the nth edge of the polygon, relative to
the nth point. If you want to draw a given edge from the edge value, you must
first translate to the position of the starting point.
the furthest point relative to the camera.
If true, this renderable will be rendered using screen coordinates, as opposed to world coordinates. Use this, for example, to define UI elements.
default value follow
(G)ame (U)nique (Id)entifier"
a GUID will be allocated for any renderable object added
to an object container (including the app.world container)
a list of indices for all vertices composing this polygon
when true the renderable will be redrawn during the next update cycle
If true then physic collision and input events will not impact this renderable
make the renderable object persistent over level changes
A mask limits rendering elements to the shape and position of the given mask object. So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
The name of the renderable
the closest point relative to the camera
offset for shake effect
an event handler that is called when the renderable leave or enter a camera viewport
Array of points defining the Polygon
Note: If you manually change points, you must call recalcafterwards so that the changes get applied correctly.
origin point of the Polygon
the default camera projection matrix (2d cameras use an orthographic projection by default).
the screen-space projection matrix for non-default cameras. Maps coordinates so that (0,0) aligns with the camera's screenX/screenY position. Used for rendering floating elements (e.g. background layers) in the correct screen area.
the x position on the screen where this camera viewport is rendered.
the y position on the screen where this camera viewport is rendered.
an optional shader, to be used instead of the default built-in one, when drawing this renderable (WebGL only).
Use ShaderEffect for a custom fragment apply() function,
or one of the built-in effect presets:
Use GLShader for full control over vertex and fragment shaders. In Canvas mode, this property is ignored.
enable or disable damping
target to follow
The shape type (used internally).
Whether to update this object when the game is paused.
If true, this floating renderable will be rendered by all cameras (e.g. background image layers). If false (default), floating elements are only rendered by the default camera (e.g. UI/HUD elements). Only applies to floating renderables in multi-camera setups.
the world-space projection matrix for non-default cameras (offset/zoomed). Maps world coordinates to the camera's screen viewport.
bottom coordinate of the Rectangle
absolute center of this rectangle on the horizontal axis
absolute center of this rectangle on the vertical axis
the depth of this renderable on the z axis
height of the Rectangle
Whether this camera is using default settings (no screen offset, no zoom). Non-default cameras use custom projections for viewport positioning and scaling.
true if this camera has no screen offset and zoom is 1
The left coordinate of the Rectangle.
returns the parent application (or game) to which this renderable is attached to
the parent application or undefined if not attached to any container/app
right coordinate of the Rectangle
top coordinate of the Rectangle
width of the Rectangle
The world-space bounds currently visible through this camera, taking into account position and zoom level.
the visible world area
return the angle to the specified target
angle in radians
center the rectangle position around the given coordinates
the x coordinate around which to center this rectangle
the y coordinate around which to center this rectangle
this rectangle
Returns true if the polygon contains the given point.
(Note: it is highly recommended to first do a hit test on the corresponding
bounding rect, as the function can be highly consuming with complex shapes)
x coordinate or a vector point to check
y coordinate
True if the polygon contain the point, otherwise false
Returns true if the polygon contains the given point.
(Note: it is highly recommended to first do a hit test on the corresponding
bounding rect, as the function can be highly consuming with complex shapes)
True if the polygon contain the point, otherwise false
Returns true if the rectangle contains the given rectangle
rectangle to test
True if the rectangle contain the given rectangle, otherwise false
return the distance to the specified target
distance
Check if this rectangle is identical to the specified one.
Other rectangle.
true if equals
fadeIn effect
fade to the specified color
a CSS color value
Optionalduration: number = 1000expressed in milliseconds
OptionalonComplete: () => voidcallback once effect is over
fadeOut(flash) effect
screen is filled with the specified color and slowly goes back to normal
a CSS color value
Optionalduration: number = 1000expressed in milliseconds
OptionalonComplete: () => voidcallback once effect is over
flip the renderable on the horizontal axis (around the center of the renderable)
Optionalflip: boolean = truetrue to flip this renderable.
Reference to this object for method chaining
flip the renderable on the vertical axis (around the center of the renderable)
Optionalflip: boolean = truetrue to flip this renderable.
Reference to this object for method chaining
set the camera position around the specified object
the renderable to focus the camera on
set the camera to follow the specified renderable.
(this will put the camera center around the given target)
renderable or position vector to follow
Optionalaxis: numberWhich axis to follow (see Camera2d.AXIS)
Optionaldamping: numberdefault damping value
return the renderable absolute position in the game world
returns the bounding box for this renderable
bounding box Rectangle object
returns a list of indices for all triangles defined in this polygon
an array of vertex indices for all triangles forming this polygon.
get the renderable alpha channel value
current opacity value between 0 and 1
Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
true if the vertices are convex, false if not, null if not computable
Determines whether all coordinates of this rectangle are finite numbers.
false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
check if the specified renderable is in the camera
to be checked against
Optionalfloating: boolean = obj.floatingif visibility check should be done against screen coordinates
true if within the viewport
convert the given "local" (screen) coordinates into world coordinates
the x coordinate of the local point to be converted
the y coordinate of the local point to be converted
Optionalv: Vector2dan optional vector object where to set the converted value
the converted world coordinates as a Vector2d
Rotate this renderable towards the given target.
the renderable or position to look at
Reference to this object for method chaining
onCollision callback, triggered in case of collision, when this renderable body is colliding with another one
true if the object should respond to the collision (its position and velocity will be corrected)
// collision handler
onCollision(response) {
if (response.b.body.collisionType === me.collision.types.ENEMY_OBJECT) {
// makes the other object solid, by substracting the overlap vector to the current position
this.pos.sub(response.overlapV);
this.hurt();
// not solid
return false;
}
// Make the object solid
return true;
},
OnDestroy Notification function
Called by engine before deleting the object
check if this rectangle is intersecting with the specified one
Other rectangle.
true if overlaps
restore the rendering context after drawing (automatically called by melonJS).
a renderer object
Prepare the rendering context before drawing (automatically called by melonJS). This will apply any defined transforms, anchor point, tint or blend mode and translate the context accordingly to this renderable position.
a renderer object
Computes the calculated collision polygon.
This must be called if the points array, angle, or offset is modified manually.
Reference to this object for method chaining
reset the camera position to specified coordinates
Optionalx: number = 0initial position of the camera on the x axis
Optionaly: number = 0initial position of the camera on the y axis
resize the camera
new width of the camera
new height of the camera
this camera
Rotate this renderable by the specified angle (in radians). When called with just an angle, rotates around the Z axis (2D rotation). When called with an angle and a Vector3d axis, rotates around that axis in 3D.
The angle to rotate (in radians)
Optionalv: anythe axis to rotate around (defaults to Z axis for 2D)
Reference to this object for method chaining
scale the renderable around his anchor point. Scaling actually applies changes to the currentTransform member which is used by the renderer to scale the object when rendering. It does not scale the object itself. For example if the renderable is an image, the image.width and image.height properties are unaltered but the currentTransform member will be changed.
a number representing the abscissa of the scaling vector.
Optionaly: number = xa number representing the ordinate of the scaling vector.
Optionalz: number = 1a number representing the depth of the scaling vector.
Reference to this object for method chaining
scale the renderable around his anchor point
scaling vector
Reference to this object for method chaining
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.
world left limit
world top limit
world width limit
world height limit
set the renderable alpha channel value
opacity value between 0.0 and 1.0
set new value to the Polygon
position of the Polygon
position of the Polygon
array of vector or vertices defining the Polygon
this instance for object chaining
Set new dimensions for the rectangle.
The new width of the rectangle.
The new height of the rectangle.
set the vertices defining this Polygon
array of vector or vertices defining the Polygon
this instance for object chaining
Set the camera screen position and size in a single call.
x position on screen
y position on screen
Optionalw: numberwidth (defaults to current width)
Optionalh: numberheight (defaults to current height)
this camera for chaining
shake the camera
maximum offset that the screen can be moved while shaking
expressed in milliseconds
Optionalaxis: numberspecify on which axis to apply the shake effect (see Camera2d.AXIS)
OptionalonComplete: () => voidcallback once shaking effect is over
Optionalforce: booleanif true this will override the current effect
apply an isometric projection to this shape
Reference to this object for method chaining
Returns a polygon whose edges are the same as this box.
a new Polygon that represents this rectangle.
multiply the renderable currentTransform with the given matrix
the transformation matrix
Reference to this object for method chaining
Translate the renderable by the specified offset.
x offset
Optionaly: number = 0y offset
Optionalz: number = 0z offset
Reference to this object for method chaining
unfollow the current target
update the bounding box for this shape.
Optionalabsolute: boolean = trueupdate the bounds size and position in (world) absolute coordinates
this shape bounding box Rectangle object
convert the given world coordinates into "local" (screen) coordinates
the x world coordinate to be converted
the y world coordinate to be converted
Optionalv: Vector2dan optional vector object where to set the converted value
a vector with the converted local coordinates
a 2D orthographic camera
Example