How to destroy particle system properly?

M

meme

Guest
Hello there! I know this type of question has been asked frequently, but I still don't get how to destroy particle system properly. So this is how I construct my particle system:

GML:
// The main particle system
global.partSystem = part_system_create();


global.partPlayer = {
    trail : 0,
    bullet : 0,
    bulletEnd : 0,
}

So the required particles are stored inside global.partPlayer struct. This is how I initialize each of the particle inside the struct:
Code:
// Trail
var _trail = part_type_create();
part_type_sprite(_trail, smCircle4, 0, 0, 0);
part_type_life(_trail, 50, 60);
part_type_size(_trail, 0.5, 0.8, 0, 0);
part_type_speed(_trail, 0.02, 0.03, 0, 0);
part_type_direction(_trail, 85, 95, 0, 0);
part_type_color2(_trail, $4f4f4f, $b6b6b6);
part_type_alpha2(_trail, 1, 0);
part_type_orientation(_trail, -10, 10, 5, 0, 0);

global.partPlayer.trail = _trail;


// Bullet
var _bullet = part_type_create();
part_type_sprite(_bullet, smBit1x1, 0, 0, 1);
part_type_life(_bullet, 50, 60);
part_type_size(_bullet, 0.8, 1, -0.025, 0);
part_type_speed(_bullet, 0.05, 0.08, 0, 0);
part_type_direction(_bullet, 75, 115, 0, 0);
part_type_color1(_bullet, global.auraColor);
part_type_orientation(_bullet, -45, 45, 0, 0, 0);

global.partPlayer.bullet = _bullet;


// And so on...

Finally, in the clean up event I just do:
part_system_destroy(global.partSystem);

I don't know whether destroying the system will destroy all particle types inside it. Do I actually need to iterate through the struct and delete the particle type 1 by 1?
Thank you for reading, if u have any suggestion feel free to share!
 

curato

Member
if you trying to clean up particle type when you done with them or closing the game it is part_type_destroy and part_system_destroy you need to use. If you wanting to just stop the particle like on level change or something where they don't make sense anymore part_particles_clear is what you need.

so you would part_type_destroy each particle type then the destroy system with part_system destroy. part_particles_clear must be used per type of particle.
 
M

meme

Guest
if you trying to clean up particle type when you done with them or closing the game it is part_type_destroy and part_system_destroy you need to use. If you wanting to just stop the particle like on level change or something where they don't make sense anymore part_particles_clear is what you need.

so you would part_type_destroy each particle type then the destroy system with part_system destroy. part_particles_clear must be used per type of particle.
Oh thanks for the info! This is what I've done in the clean up event:
GML:
// Destroy particle
part_system_destroy(global.partSystem);


// Destroy particles in structs
var _structArr = [global.partPlayer, global.partObstacle];

for (var i = 0;i < array_length(_structArr);i++)
{
    // Access each structs
    var _keys = variable_struct_get_names(_structArr[i]);
    
    // Loop through all particles
    for (var j = 0; j < array_length(_keys); j++;)
    {
        part_type_destroy(variable_struct_get(_structArr[i], _keys[j]));
    }
}
 
Top