//*********************************************************************************
//                   SPARK Wrapper PointSprite Demo
//        
//*********************************************************************************


// turn on the backdrop

backdrop on
color backdrop 0

//********* we load our texture for particles

load image "media\point.bmp",1


// create the particle system as usual , but this time we create a protoType system
// in this demo we create some basic firework effect.

FireworksPrototype = sp create system (1,0,0,0)

// Now we set the prototype system autodeletion to 1.This ensures all
// instances of this system will be deleted automatically if becomes
// inactive.

sp set system autodelete FireworksPrototype , 1

// we add one group to the system.

group = sp add group (FireworksPrototype , 250 , 0.01 ,0,0,0)

// set his lifetime

sp set group lifetime group , 6 , 7


// and now we add a point sprite renderer to the group.
// It's not recommended to use this type of renderer ever in youre game/app
// it's lot faster then the quad renderer , but the quad renderer
// has way more features which the point renderer hasn't :
// Point sprites cannot be rotated
// Point sprites have no Atlas dimensions
// Point sprites are 3d sprites (2d image in 3d space) which means they cannot be 
// scaled !
// So the final conclusion is that most of interpolators will not work
// on the point renderer ! (You can add them but will have no effect at all)
// But still in some special cases it becomes very handy.Rendering sparks , 
// or creating firework effects (like we do in this demo) simulating
// dust , etc
 
renderer = sp set point renderer (group , 1 ,0.01 , BLEND_ADD)

// the first parameter is the GroupID , the second is the image id , the 3rd is the 
// point size (size of the sprites) and the 4th parameter is the blending mode.


// ok now we set a simple rgba interpolator to our group ensure the particles
// are born with a red color and dies with a purple color

rgbaInterpolator = sp add rgba interpolator (group , sp rgba(10 , 120 , 50 ,255) , sp rgba(255 , 10 , 10 ,0) , 0)


// we add a random emitter to the group.So particles will be emited in random
// direction.And set the flow parameter to -1
// This means all the particles in the emitter's tank must be emited at once 
// We define a point zone , so the particles will be emited from a 
// point.

emitter = sp add random emitter (group,-1, 1 , 1.5 , 150 , sp point zone(0,0,0))


// Particles have no gravity by default.So we add a gravity modifier
// to our group.

gravity = sp add gravity modifier (group,0,-1.5,0)


// all we have to do is updating the scene !
// We use some small additional code for creating instances.When we press the 
// mouse button a new Firework System will be created at random position.


do


position camera 0,0,0,0
rotate camera 0 ,camera angle x(0)+ mousemovey()*0.2 , camera angle y(0)+ mousemovex()*0.2 ,0
move camera 0,-10

if mouseclick() = 1 and hold = 0
    newFirework = sp copy system( FireworksPrototype , rnd(5) , rnd(5) , rnd(5))
    hold = 1
    endif
    
if mouseclick() = 0 then hold = 0

sp update


loop
 







