GML Functions: Firework Example

Here is an example of a particle system that creates fireworks. The firework uses two particle types: one that forms the rocket and one that forms the actual fireworks. The rocket generates the firework particles when it dies. We also generate one emitter in the particle system that regularly stream out rocket particles along the bottom of the screen. To make this work you need an object. In its creation event we place the following code that creates the particle types, particle system, and the emitter:

{ // make the particle system ps = part_system_create; // the firework particles pt1 = part_type_create; part_type_shape(pt1,pt_shape_flare); part_type_size(pt1,0.1,0.2,0,0); part_type_speed(pt1,0.5,4,0,0); part_type_direction(pt1,0,360,0,0); part_type_color1(pt1,c_red); part_type_alpha2(pt1,1,0.4); part_type_life(pt1,20,30); part_type_gravity(pt1,0.2,270); // the rocket pt2 = part_type_create; part_type_shape(pt2,pt_shape_sphere); part_type_size(pt2,0.2,0.2,0,0); part_type_speed(pt2,10,14,0,0); part_type_direction(pt2,80,100,0,0); part_type_color2(pt2,c_white,c_gray); part_type_life(pt2,30,60); part_type_gravity(pt2,0.2,270); part_type_death(pt2,150,pt1);   // create the firework on death // create the emitter em = part_emitter_create(ps); part_emitter_region(ps,em,100,540,480,490,ps_shape_rectangle,ps_distr_linear); part_emitter_stream(ps,em,pt2,-4);  // create one every four steps } That will do the trick. You might want to make sure the particle system (and maybe particle types) are destroyed when moving to another room, otherwise the firework will continue forever.