Simple particle library

File:
SimpleParticle.lib
Version:
1.0
Author:
Marcus Johansson

Contents

Details
Sub routines


Details

A library for simple particle effects.


Subroutines

Name
Parameters
Brief description
procedure
SP_Init
maxParticles
Init library.
procedure
SP_AddParticle
img, cel, addMode, x, y, srcDX#, srcDY#, dstDX#, dstDY#, srcAlpha#, dstAlpha#, speed#, pause
Add a particle.
procedure
SP_AddPoof
img, cel, x, y, particleCount, distance#, force#, speed#, addMode, fadeOut
Add poof effect.
procedure
SP_AddRandomPoof
img, cel, x, y, particleCount, maxDistance#, maxForce#, maxSpeed#, addMode, fadeOut
Add random poof effect.
procedure
SP_SetPoofEndVector
ex#, ey#
Set end vector for poof-generated particles.
procedure
SP_AddParticleAt
x, y
Add a particle with current settings.
procedure
SP_SetImage
img, cel, addMode
Set particle image properties for 'SP_AddParticleAt'.
procedure
SP_SetDirection
srcDX#, srcDY#, dstDX#, dstDY#
Set particle directions for 'SP_AddParticleAt'.
procedure
SP_SetAlpha
srcAlpha#, dstAlpha#
Set particle alpha for 'SP_AddParticleAt'.
procedure
SP_SetSpeed
speed#
Set parameter speed for 'SP_AddParticleAt'.
procedure
SP_SetPause
pause
Set delay for 'SP_AddParticleAt'.
procedure
SP_UpdateParticles
Update all particles.
procedure
SP_DrawParticles
Draw all particles.
procedure
SP_DrawParticlesAt
x, y
Update all particles with an offset.
procedure
SP_DoParticles
Update and draw all particles.
procedure
SP_DoParticlesAt
x, y
Update and draw all particles with an offset.


Subroutine documentation

procedure SP_Init ( maxParticles )

You must call this procedure before adding any particles. You can set the maximum number of active particles live at a time.

Parameter
Mode
Description
maxParticles
In
Max live particles.

[ Back ]


procedure SP_AddParticle ( img, cel, addMode, x, y, srcDX#, srcDY#, dstDX#, dstDY#, srcAlpha#, dstAlpha#, speed#, pause )

The life time of a particle depends on the FPS at which your game is running. The particle uses a parameter that's increased by 'speed' every time you call 'SP_UpdateParticles' or 'SP_DoParticles'. It starts at 0 and when it reaches 1 the particle dies.

Parameter
Mode
Description
img
In
Id of image to use.
cel
In
Cel of image to use. Set to -1 for an animation of all cels or -2 for a random cel.
addMode
In
True for additive drawing.
x
In
Start x-coordinate.
y
In
Start y-coordinate.
srcDX
In
Start x increment (when parameter is 0).
srcDY
In
Start y increment (when parameter is 0).
dstDX
In
End x increment (when parameter is 1).
dstDY
In
End y increment (when parameter is 1).
srcAlpha
In
Start alpha/transparency, where 1 is opaque and 0 is transparent.
dstAlpha
In
End alpha/transparency.
speed
In
Parameter increment.
pause
In
Delay before particle is born. Decreased by 1 during each update.

[ Back ]


procedure SP_AddPoof ( img, cel, x, y, particleCount, distance#, force#, speed#, addMode, fadeOut )

Add particles equaly spread around a growing circle.

Parameter
Mode
Description
img
In
Image id.
cel
In
Image cel. As for single particles, -1 is for animation and -2 for random cels.
x
In
Center x-coordinate.
y
In
Center y-coordinate.
particleCount
In
Number of particles.
distance
In
Starting distance from '(x, y)'.
force
In
Size of movement vector at start.
speed
In
Parameter increment per update.
addMode
In
True for additive drawing.
fadeOut
In
True for particles with alpha starting at 255 and ending at 0.

[ Back ]


procedure SP_AddRandomPoof ( img, cel, x, y, particleCount, maxDistance#, maxForce#, maxSpeed#, addMode, fadeOut )

Works like 'SP_AddPoof', but with slightly randomized properties for particles.

Parameter
Mode
Description
img
In
Image id.
cel
In
Image cel. As for single particles, -1 is for animation and -2 for random cels.
x
In
Center x-coordinate.
y
In
Center y-coordinate.
particleCount
In
Number of particles.
distance
In
Max starting distance from '(x, y)'.
force
In
Max size of movement vector at start.
speed
In
Max parameter increment per update.
addMode
In
True for additive drawing.
fadeOut
In
True for particles with alpha starting at 255 and ending at 0.

[ Back ]


procedure SP_SetPoofEndVector ( ex#, ey# )

By default the end vector for poof-generated particles is (0, 0). If you want, for example, want a gravity effect, you could set the end vector to 0, 4.

Parameter
Mode
Description
ex
In
End x-increment.
ey
In
End y-increment

[ Back ]


procedure SP_AddParticleAt ( x, y )

Add a particle with settings defined with 'SP_SetImage', 'SP_SetDirection', 'SP_SetAlpha', 'SP_SetSpeed' and 'SP_SetPause'.

Parameter
Mode
Description
X-coordinate.
In
Y-coordinate.
In

[ Back ]


procedure SP_SetImage ( img, cel, addMode )

Set particle image properties for 'SP_AddParticleAt'.

Parameter
Mode
Description
img
In
Image id.
cel
In
Image Cel (-1 for animation, -2 for randomized cel).
addMode
In
True for additive drawing.

[ Back ]


procedure SP_SetDirection ( srcDX#, srcDY#, dstDX#, dstDY# )

Set particle directions for 'SP_AddParticleAt'.

Parameter
Mode
Description
srcDX
In
Start x increment.
srcDY
In
Start y increment.
dstDX
In
End x increment.
dstDY
In
End y increment.

[ Back ]


procedure SP_SetAlpha ( srcAlpha#, dstAlpha# )

Set particle alpha for 'SP_AddParticleAt'.

Parameter
Mode
Description
srcAlpha
In
Start alpha/transparency, where 1 is opaque and 0 is transparent.
dstAlpha
In
End alpha/transparency.

[ Back ]


procedure SP_SetSpeed ( speed# )

Set parameter speed for 'SP_AddParticleAt'.

Parameter
Mode
Description
speed
In
Parameter speed.

[ Back ]


procedure SP_SetPause ( pause )

Set delay for 'SP_AddParticleAt'.

Parameter
Mode
Description
pause
In
Delay.

[ Back ]


procedure SP_UpdateParticles ( )

Update all particles.

[ Back ]


procedure SP_DrawParticles ( )

Draw all particles.

[ Back ]


procedure SP_DrawParticlesAt ( x, y )

Update all particles with an offset.

Parameter
Mode
Description
x
In
X offset.
y
In
Y offset.

[ Back ]


procedure SP_DoParticles ( )

Update and draw all particles.

[ Back ]


procedure SP_DoParticlesAt ( x, y )

Update and draw all particles with an offset.

Parameter
Mode
Description
x
In
X offset.
y
In
Y offset.

[ Back ]


Generated with NLDoc 20140630.