Moscrif API Docs for: 2012q3
Show:

Particle Class

include "lib://game2d/particle/particle.ms";
Library: game2d

Particle is a abstract entity with a small set of attributes such as position and color that ultimately dictate the particle's behavior and appearance. This class is a base class for classes, whih are used to create particles.

Item Index

Attributes

Events

Methods

alive

()

Check if particle is a live.

draw

(
  • canvas
)

Method draw defines action whithin onDraw. This method can be overwriten to customize particle appearance.

Parameters:

  • canvas Canvas

    canvas used to draw graphics

Example:

// owerwrite ancestor's draw function
function draw(canvas)
{
    // set bitmap translate acording to actual particle position
    this._matrix.translateX = this._position.x;
    this._matrix.translateY = this._position.y;
    canvas.drawBitmapMatrix(MyParticle.img, this._matrix, MyParticle.paint);
}

init

() protected

Init instance. The init method sets all needed fields properties acording to developer requirements or to default values. This method is called when field object is constructed.

move

()

Method to move particle based on acceleration and velocity vector.

submitToFields

(
  • fields
)

This function affect particle's movement by a force fields.

Parameters:

  • fields Array

    Array of Field

Properties

acceleration

Vector

Particle acceleration

lived

Integer

Age of the particle, define time how long particle can be alive.

position

Vector

Location of the particle center.

Example:

// owerwrite ancestor's draw function
function draw(canvas)
{
    // set bitmap translate acording to actual particle position
    this._matrix.translateX = this._position.x;
    this._matrix.translateY = this._position.y;
    // draw custom particle bitmap
    canvas.drawBitmapMatrix(MyParticle.img, this._matrix, MyParticle.paint);
}

ttl

Integer

Time to live in milliseconds, default is set to -1, which menas live forever.

velocity

Vector

Velocity vector of the particle. The initial velocity is given to the particle, when it is emitted from emitter.

Attributes

paint

Paint static

Singleton of the paint object.

Events

onDraw

Event fired on Draw of particle.

Event Payload:

  • canvas Canvas

    canvas used to draw graphics