Home Reference Source
public class | source

Collision

Extends:

Behaviour → Collision

Behaviour that causes particles to move away from other particles they collide with.

Constructor Summary

Public Constructor
public

constructor(emitter: Emitter, useMass: boolean, onCollide: function, life: number, easing: function, isEnabled: boolean): *

Constructs a Collision behaviour instance.

Member Summary

Public Members
public

delta: *

public

emitter: *

public
public

particles: *[]

public

useMass: *

Method Summary

Public Methods
public

fromJSON(json: *)

public

mutate(particle: Particle, time: number, index: integer): *

Detects collisions with other particles and calls the onCollide function on colliding particles.

public

reset(emitter: Emitter, useMass: boolean, onCollide: function, life: number, easing: function): *

Resets the behaviour properties.

Private Methods
private

_getAverageMass(particleA: Particle, particleB: Particle): number

Gets the average mass of both particles.

Inherited Summary

From class Behaviour
public get

life: Number: *

Gets the behaviour's life.

public set

life: *

Ensures that life is infinity if an invalid value is supplied.

public

The age of the behaviour

public

Determines if the behaviour is dead or not

public

The behaviour's decaying trend

public

The energy of the behaviour

public

The behaviour's id

public

Determines if the behaviour will be applied or not

public

The class type.

private

_life: *

public abstract

applyBehaviour(target: Particle | Emitter, time: Number, index: integer): *

Apply behaviour to the target as a factor of time.

public abstract

Destory this behaviour.

public

energize(particle: Particle, time: Number): *

Compares the age of the behaviour vs integration time and determines if the behaviour should be set to dead or not.

public abstract

Returns a new instance of the behaviour from the JSON object passed.

public abstract

initialize(particle: Particle)

Set the behaviour's initial properties on the particle.

public abstract

mutate(target: Particle | Emitter, time: Number): *

Change the target's properties according to specific behaviour logic.

public

Normalize a force by 1:100;

public

Normalize a value by 1:100;

public

reset(life: number, easing: function)

Reset this behaviour's parameters

Public Constructors

public constructor(emitter: Emitter, useMass: boolean, onCollide: function, life: number, easing: function, isEnabled: boolean): * source

Constructs a Collision behaviour instance.

Override:

Behaviour#constructor

Params:

NameTypeAttributeDescription
emitter Emitter

The emitter containing the particles to detect collisions against

useMass boolean

Determiens whether to use mass or not

onCollide function

Function to call when particles collide

life number

The life of the particle

easing function

The behaviour's decaying trend

isEnabled boolean
  • optional
  • default: true

Determines if the behaviour will be applied or not

Return:

*

void

Public Members

public delta: * source

public emitter: * source

public onCollide: * source

public particles: *[] source

public useMass: * source

Public Methods

public fromJSON(json: *) source

Returns a new instance of the behaviour from the JSON object passed.

Override:

Behaviour#fromJSON

Params:

NameTypeAttributeDescription
json *

public mutate(particle: Particle, time: number, index: integer): * source

Detects collisions with other particles and calls the onCollide function on colliding particles.

Override:

Behaviour#mutate

Params:

NameTypeAttributeDescription
particle Particle

the particle to apply the behaviour to

time number

particle engine time

index integer

the particle index

Return:

*

void

public reset(emitter: Emitter, useMass: boolean, onCollide: function, life: number, easing: function): * source

Resets the behaviour properties.

Override:

Behaviour#reset

Params:

NameTypeAttributeDescription
emitter Emitter

The emitter containing the particles to detect collisions against

useMass boolean

Determiens whether to use mass or not

onCollide function

Function to call when particles collide

life number

The life of the particle

easing function

The behaviour's decaying trend

Return:

*

void

Private Methods

private _getAverageMass(particleA: Particle, particleB: Particle): number source

Gets the average mass of both particles.

Params:

NameTypeAttributeDescription
particleA Particle

The first particle

particleB Particle

The second particle

Return:

number