Class: Particle

Particle(texture, x, y, life) → {Particle}

Defines a square particle that has physics support. The size and color of a particle can change over a set lifetime.

Found in Chapter 10, page 649 of the textbook

Examples: 10.1 Simple Particles, 10.2 Particle Collision, 10.3 Particle Emitters

Constructor

new Particle(texture, x, y, life) → {Particle}

Parameters:
Name Type Description
texture string path to the texture file for this Particle
x float starting X world coordinate
y float starting Y world coordinate
life integer number of cycles this particle lives for
Source:
Returns:
a new Particle instance
Type
Particle

Methods

draw(aCamera)

Draw the ParticleRenderable of this Particle to the Camera
Parameters:
Name Type Description
aCamera Camera the Camera to draw to
Source:

drawMarker(aCamera)

Draw a cross marker on this Particle for debugging
Parameters:
Name Type Description
aCamera Camera the Camera to draw to
Source:

getAcceleration() → {vec2}

Returns the X,Y world coordinate acceleration vector of this Particle
Source:
Returns:
mAcceleration - acceleration vector
Type
vec2

getColor() → {vec4}

Returns the current color of this particle
Source:
Returns:
[R,G,B,A] color array
Type
vec4

getDrag() → {float}

Returns the drag value of this Particle
Source:
Returns:
mDrag - drag value
Type
float

getDrawBounds() → {boolean}

Returns whether the bounds are set to be drawn
Source:
Returns:
mDrawBounds - true if bounds are being drawn
Type
boolean

getPosition() → {vec2}

Returns the X,Y world coordinate position of this Particle
Source:
Returns:
current position vector
Type
vec2

getSize() → {float}

Returns the current world coordinate size of this Particle
Source:
Returns:
the Particle's size
Type
float

getVelocity() → {vec}

Returns the X,Y world coordinate velocity vector of this Particle
Source:
Returns:
mVelocity - velocity vector
Type
vec

hasExpired() → {boolean}

Returns whether this Particle has reached the end of its lifetime
Source:
Returns:
true if lifetime has ended
Type
boolean

setAcceleration(x, y)

Set the X,Y world coordinate acceleration vector of this Particle
Parameters:
Name Type Description
x float horizontal acceleration
y float vertical acceleration
Source:

setColor(c)

Set the current color of this Particle
Parameters:
Name Type Description
c vec4 [R,G,B,A] color array
Source:

setDrag(d)

Set the velocity drag multiplier of this Particle

On update calls the velocity is multiplied by this value

Parameters:
Name Type Description
d float drag multiplier value
Source:

setDrawBounds(d)

Set whether the bounds of this Particle are drawn
Parameters:
Name Type Description
d boolean true to draw bounds
Source:

setFinalColor(f)

Set the final color for this Particle by changing the delta color accordingly
Parameters:
Name Type Description
f vec4 final target [R,G,B,A] color array
Source:

setPosition(xPos, yPos)

Set the X,Y world coordinate position of this Particle
Parameters:
Name Type Description
xPos float the new X position
yPos float the new Y position
Source:

setSize(x, y)

Set the X and Y world coordinate size of this Particle
Parameters:
Name Type Description
x float horizontal size
y float vertical size
Source:

setSizeDelta(d)

Set the size changing factor

On update calls the size is multiplied by this value

Parameters:
Name Type Description
d float multipier applied on every update
Source:

setVelocity(x, y)

Set the X,Y world coordinate velocity vector of this Particle
Parameters:
Name Type Description
x float horizontal velocity
y float vertical velocity
Source:

update()

Update the position, velocity, size, and color of this Particle
Source: