x position of the particle emitter
y position of the particle emitter
Optional
settings: { the settings for the particle emitter.
Start angle for particle launch in Radians
letiation in the start angle for particle launch in Radians.
the blend mode to be applied when rendering particles.
(note: this will superseed the textureAdditive
setting if different than "normal")
Duration that the emitter releases particles in ms (used only if emitter is Stream). After this period, the emitter stop the launch of particles.
Render particles in screen space.
Update the rotation of particle in accordance the particle trajectory.
The particle sprite should aim at zero angle (draw from left to right).
Override the particle minRotation and maxRotation.
Skip n frames after updating the particle system once. This can be used to reduce the performance impact of emitters with many particles.
How often a particle is emitted in ms (used only if emitter is a Stream).
Vertical force (Gravity) for each particle
Height of the particle spawn area
image used for particles texture (by default melonJS will create an white 8x8 texture image)
Maximum end scale ratio for particles
Maximum time each particle lives once it is emitted in ms.
Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
Maximum start rotation for particles sprites in Radians
Maximum start scale ratio for particles (1 = no scaling)
Minimum end scale ratio for particles
Minimum time each particle lives once it is emitted in ms.
Minimum start rotation for particles sprites in Radians
Minimum start scale ratio for particles (1 = no scaling)
Update particles only in the viewport, remove it when out of viewport.
Start speed of particles.
letiation in the start speed of particles
Enable the Texture Additive by composite operation ("additive" blendMode)
default texture size used for particles if no image is specified (by default melonJS will create an white 8x8 texture image)
tint to be applied to particles
Total number of particles in the emitter
Width of the particle spawn area.
Horizontal force (like a Wind) for each particle
// Create a particle emitter at position 100, 100
let emitter = new ParticleEmitter(100, 100, {
width: 16,
height : 16,
tint: "#f00",
totalParticles: 32,
angle: 0,
angleVariation: 6.283185307179586,
maxLife: 5,
speed: 3
});
// Add the emitter to the game world
me.game.world.addChild(emitter);
// Launch all particles one time and stop, like a explosion
emitter.burstParticles();
// Launch constantly the particles, like a fountain
emitter.streamParticles();
// At the end, remove emitter from the game world
// call this in onDestroyEvent function
me.game.world.removeChild(emitter);
(G)ame (U)nique (Id)entifier"
a GUID will be allocated for any renderable object added
to an object container (including the me.game.world
container)
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}
.
Specify if the children z index should automatically be managed by the parent container
Specify if the children list should be automatically sorted when adding a new child
When enabled, an object container will automatically apply any defined transformation before calling the child draw method.
true
// 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;
....
}
define a background color for this container
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
me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
}
...
}
Specify if the container draw operation should clip his children to its own bounds
the renderable default transformation matrix
The edges here are the direction of the n
th edge of the polygon, relative to
the n
th point. If you want to draw a given edge from the edge value, you must
first translate to the position of the starting point.
Specify if the container bounds should automatically take in account all child bounds when updated (this is expensive and disabled by default, only enable if necessary)
If true, this renderable will be rendered using screen coordinates, as opposed to world coordinates. Use this, for example, to define UI elements.
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.
undefined
// apply a mask in the shape of a Star
myNPCSprite.mask = new me.Polygon(myNPCSprite.width / 2, 0, [
// draw a star
{x: 0, y: 0},
{x: 14, y: 30},
{x: 47, y: 35},
{x: 23, y: 57},
{x: 44, y: 90},
{x: 0, y: 62},
{x: -44, y: 90},
{x: -23, y: 57},
{x: -47, y: 35},
{x: -14, y: 30}
]);
The name of the renderable
a callback to be extended, triggered after a child has been added or removed
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 recalc
afterwards so that the changes get applied correctly.
origin point of the Polygon
whether the container is the root of the scene
the current (active) emitter settings
Start angle for particle launch in Radians
letiation in the start angle for particle launch in Radians.
the blend mode to be applied when rendering particles.
(note: this will superseed the textureAdditive
setting if different than "normal")
Duration that the emitter releases particles in ms (used only if emitter is Stream). After this period, the emitter stop the launch of particles.
Render particles in screen space.
Update the rotation of particle in accordance the particle trajectory.
The particle sprite should aim at zero angle (draw from left to right).
Override the particle minRotation and maxRotation.
Skip n frames after updating the particle system once. This can be used to reduce the performance impact of emitters with many particles.
How often a particle is emitted in ms (used only if emitter is a Stream).
Vertical force (Gravity) for each particle
Height of the particle spawn area
image used for particles texture (by default melonJS will create an white 8x8 texture image)
Maximum end scale ratio for particles
Maximum time each particle lives once it is emitted in ms.
Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
Maximum start rotation for particles sprites in Radians
Maximum start scale ratio for particles (1 = no scaling)
Minimum end scale ratio for particles
Minimum time each particle lives once it is emitted in ms.
Minimum start rotation for particles sprites in Radians
Minimum start scale ratio for particles (1 = no scaling)
Update particles only in the viewport, remove it when out of viewport.
Start speed of particles.
letiation in the start speed of particles
Enable the Texture Additive by composite operation ("additive" blendMode)
default texture size used for particles if no image is specified (by default melonJS will create an white 8x8 texture image)
tint to be applied to particles
Total number of particles in the emitter
Width of the particle spawn area.
Horizontal force (like a Wind) for each particle
(Experimental) an optional shader, to be used instead of the default built-in one, when drawing this renderable (WebGL only)
The property of the child object that should be used to sort on this container value : "x", "y", "z"
The shape type (used internally).
Whether to update this object when the game is paused.
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 the renderable object is visible and within the viewport
returns true if this renderable is flipped on the horizontal axis
returns true if this renderable is flipped on the vertical axis
Whether the renderable object is floating (i.e. used screen coordinates), or contained in a floating parent container
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
Add a child to the container
if auto-sort is disable, the object will be appended at the bottom of the list.
Adding a child to the container will automatically remove it from its other container.
Meaning a child can only have one parent. This is important if you add a renderable
to a container then add it to the World container it will move it out of the
orginal container. Then when the World container reset() method is called the renderable
will not be in any container.
if the given child implements a onActivateEvent method, that method will be called
once the child is added to this container.
Child to be added
Optional
z: numberforces the z index of the child to the specified value
the added child
Add a child to the container at the specified index
(the list won't be sorted after insertion)
Child to be added
The index at which to insert the child
the added child
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
copy the position and size of the given rectangle into this one
Source rectangle
new rectangle
draw this renderable (automatically called by melonJS)
a renderer instance
Optional
viewport: anythe viewport to (re)draw
Check if this rectangle is identical to the specified one.
Other rectangle.
true if equals
flip the renderable on the horizontal axis (around the center of the renderable)
Optional
flip: 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)
Optional
flip: boolean = truetrue
to flip this renderable.
Reference to this object for method chaining
The forEach() method executes a provided function once per child element.
the callback function is invoked with three arguments:
fnction to execute on each element
Optional
thisArg: objectvalue to use as this(i.e reference Object) when executing callback.
Returns the Child at the specified index
The index of the child
the child at the specified index
return the child corresponding to the specified GUID
note : avoid calling this function every frame since
it parses the whole object list each time
child GUID
corresponding child or null
returns the list of childs with the specified name
as defined in Tiled (Name field of the Object Properties)
note : avoid calling this function every frame since
it parses the whole object list each time
child name
Array of children
return the child corresponding to the given property and value.
note : avoid calling this function every frame since
it parses the whole object tree each time
Property name
Value of the property
Array of childs
// get the first child object called "mainPlayer" in a specific container :
let ent = myContainer.getChildByProp("name", "mainPlayer");
// or query the whole world :
let ent = container.getChildByProp("name", "mainPlayer");
// partial property matches are also allowed by using a RegExp.
// the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
let allCoins = container.getChildByProp("name", /coin/i);
// searching for numbers or other data types :
let zIndex10 = container.getChildByProp("z", 10);
let inViewport = container.getChildByProp("inViewport", true);
returns the list of childs with the specified class type
Class type
Array of children
Returns the index of the given Child
The child object
index
return all child in this container
an array of renderable object
Returns the next child within the container or undefined if none
The child object
child
Returns true if contains the specified Child
The child object
Rotate this renderable towards the given target.
the renderable or position to look at
Reference to this object for method chaining
Move the child in the group one step backward (z depth).
Child to be moved
Move the specified child the bottom (z depth).
Child to be moved
Move the specified child to the top(z depth).
Child to be moved
Move the child in the group one step forward (z depth).
Child to be moved
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)
// colision 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;
},
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
Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed.
if the given child implements a onDeactivateEvent() method, that method will be called once the child is removed from this container.
Child to be removed
Optional
keepalive: booleantrue to prevent calling child.destroy()
Removes (and optionally destroys) a child from the container.
(removal is immediate and unconditional)
Never use keepalive=true with objects from pool. Doing so will create a memory leak.
Child to be removed
Optional
keepalive: booleanTrue to prevent calling child.destroy()
Reset the emitter with particle emitter settings.
[optional] object with emitter settings. See ParticleEmitterSettings
Start angle for particle launch in Radians
letiation in the start angle for particle launch in Radians.
the blend mode to be applied when rendering particles.
(note: this will superseed the textureAdditive
setting if different than "normal")
Duration that the emitter releases particles in ms (used only if emitter is Stream). After this period, the emitter stop the launch of particles.
Render particles in screen space.
Update the rotation of particle in accordance the particle trajectory.
The particle sprite should aim at zero angle (draw from left to right).
Override the particle minRotation and maxRotation.
Skip n frames after updating the particle system once. This can be used to reduce the performance impact of emitters with many particles.
How often a particle is emitted in ms (used only if emitter is a Stream).
Vertical force (Gravity) for each particle
Height of the particle spawn area
image used for particles texture (by default melonJS will create an white 8x8 texture image)
Maximum end scale ratio for particles
Maximum time each particle lives once it is emitted in ms.
Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
Maximum start rotation for particles sprites in Radians
Maximum start scale ratio for particles (1 = no scaling)
Minimum end scale ratio for particles
Minimum time each particle lives once it is emitted in ms.
Minimum start rotation for particles sprites in Radians
Minimum start scale ratio for particles (1 = no scaling)
Update particles only in the viewport, remove it when out of viewport.
Start speed of particles.
letiation in the start speed of particles
Enable the Texture Additive by composite operation ("additive" blendMode)
default texture size used for particles if no image is specified (by default melonJS will create an white 8x8 texture image)
tint to be applied to particles
Total number of particles in the emitter
Width of the particle spawn area.
Horizontal force (like a Wind) for each particle
resize the rectangle
new width of the rectangle
new height of the rectangle
this rectangle
Rotate this renderable by the specified angle (in radians).
The angle to rotate (in radians)
Optional
v: anyan optional point to rotate around
Reference to this object for method chaining
scale the renderable around his anchor point. Scaling actually applies changes to the currentTransform member wich 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.
Optional
y: number = xa number representing the ordinate 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 new value to the Polygon
position of the Polygon
position of the Polygon
array of vector or vertice defining the Polygon
this instance for objecf 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 vertice defining the Polygon
this instance for objecf chaining
Shifts the Polygon to the given position vector.
The x coordinate or a vector point to shift to.
Optional
y: numberThe y coordinate. This parameter is required if the first parameter is a number.
Swaps the position (z-index) of 2 children
Child to be added
Child to be added
apply a 2d projection to this shapen
Reference to this object for method chaining
apply an isometric projection to this shape
Reference to this object for method chaining
multiply the renderable currentTransform with the given matrix
the transformation matrix
Reference to this object for method chaining
Translates the Polygon by the specified offset.
The x offset or a vector point to translate by.
Optional
y: numberThe y offset. This parameter is required if the first parameter is a number.
Reference to this object for method chaining
merge this rectangle with another one
other rectangle to union with
the union(ed) rectangle
Particle Emitter Object.