Legacy GM need help Understanding Particles

Okay so right now im starting to get into the particle system. From what i read and understand i should probably make the particle system global to use throughout the game. From alot of tutorials that i have followed online they all put them in the create event of some sorta controller object.

So lets say if i want to use the particles for multiple objects and i want the animation of the particles to start from the beginning every time it is created. Do i create the object multiple times?? How do i stop creating the particles after a certain amount lets say i want to create like 100 from an emitter do i just set up some sorta check like
If part >=30{destroy particle system}

i guess i just want to know how to create some particle effects universally. Also how do i free up the particles from memory after switching to another room and such? Do the particles themselves that are created from an emitter free itself from memory after their lifespan is over?

should i just create a persistent object ??
 
Last edited:

Perseus

Not Medusa
Forum Staff
Moderator
So lets say if i want to use the particles for multiple objects and i want the animation of the particles to start from the beginning every time it is created. Do i create the object multiple times??
No, as you mentioned, you can use a single instance of a controller object to create the paticle system(s) / emitter(s) / type(s) and assign their indexes to global variables (preferably only once at the start of your game to avoid clutter of useless code and instances), so that they can be accessed everywhere in your game after creation. It might also be worthwhile to learn the difference between objects and instances while we're at it.

How do i stop creating the particles after a certain amount lets say i want to create like 100 from an emitter do i just set up some sorta check like
There is a function called part_particles_count() that returns the number of particles in a system. You could check if it returns a value smaller than 100 before emitting more particles to the system. Another option is to use a variable which is to get incremented every time a particle is created. It would be a more viable option if you're concerned about the execution cost of part_particles_count() and / or there are particles of multiple types in the same system but you want data of only one.

Also how do i free up the particles from memory after switching to another room and such? Do the particles themselves that are created from an emitter free itself from memory after their lifespan is over?
No, they do not clear up themselves when the room changes. You need to do it manually via part_particles_clear().
 
No, as you mentioned, you can use a single instance of a controller object to create the paticle system(s) / emitter(s) / type(s) and assign their indexes to global variables (preferably only once at the start of your game to avoid clutter of useless code and instances), so that they can be accessed everywhere in your game after creation. It might also be worthwhile to learn the difference between objects and instances while we're at it.


There is a function called part_particles_count() that returns the number of particles in a system. You could check if it returns a value smaller than 100 before emitting more particles to the system. Another option is to use a variable which is to get incremented every time a particle is created. It would be a more viable option if you're concerned about the execution cost of part_particles_count() and / or there are particles of multiple types in the same system but you want data of only one.


No, they do not clear up themselves when the room changes. You need to do it manually via part_particles_clear().
@Ragarnak
Thanks for the response, i made a little Sample project. This is how i have it setup so far

Obj_init:
Code:
Persistent = true
global.p1_sys = part_system_create();
part1_type_scr(); //Calls the script and creates the type in global.type1
part2_type_scr();
///Game End
part_type_destroy(global.part1);
part_type_destroy(global.part2);
part_system_destroy(global.p1_sys);

part1_type_scr();
Code:
///Init out global emitter particles
global.part1 =part_type_create();

var p1 = global.part1
var col=make_colour_rgb(100,149,237)

part_type_shape(p1,pt_shape_spark);
part_type_scale(p1,1,1); //Changes the shape
part_type_size(p1,0.1,0.4,-0.005,0);
part_type_color2(p1,col,c_white);
part_type_alpha2(p1,1,0.5);

part_type_speed(p1,0.1,0.5,0.01,0);
part_type_direction(p1,1,375,0,0);
part_type_gravity(p1,0.02,90);


part_type_life(p1,room_speed*2,room_speed*3);
part_type_blend(p1,1)

obj_particle
Code:
///Create
em=part_emitter_create(global.p1_sys);
part_emitter_region(global.p1_sys,em,x-40,x+40,y-40,y+40,ps_shape_ellipse,ps_distr_gaussian)
part_emitter_stream(global.p1_sys,em,global.part1,1)

//Code for Destroy, Room End and game end
part_emitter_clear(global.p1_sys, em);
part_emitter_destroy(global.p1_sys,em);

is this how its done?
 
Hello!

I do it this way, for example, a small particle system I use for some fire

I have a small sprite with the fire particles obviously, and this is the code I use in the object that generates the fire.

Create event:

///Particles
//Part system
partFire_sys = part_system_create();
part_system_depth(partDestroy_sys, -bbox_bottom);

//Fire particle
partFire = part_type_create();
part_type_sprite(partFire, spr_partSmoke5x5, 0, 0, 1);
part_type_size(partFire, 0.4, 0.5, 0, 0);
part_type_colour2(partFire,c_red,c_orange);
part_type_alpha3(partFire,0.5,1,0);
part_type_speed(partFire,0.1,0.2,0,0);
part_type_direction(partFire,85,95,0,10);
part_type_orientation(partFire,0,359,0,0,0);
part_type_life(partFire,20,40);

End step event:
///Movement particles
if random(1)<= 0.75
{
repeat(1)
{
part_particles_create(partFire_sys, random_range(x-1,x+3), random_range(y-7,y-5), partFire, 1);
}
}

I like to use the random, and repeat, to play around with different frequencies of particle spamming.

Also answering to your first post, personally, I do not use nothing related to particles in my controller object. Every object I have that uses particles, has the first script in the create event. And the second in step. I found it much easier to personalize the functionality of each object and it's particles.
 
Top