Particle System Problem

T2008

Member
I added a particle system to create rain in one room. I"m trying to get it to stop in the next room, but the rain keeps coming even though I destroy it in the room end event. My game is large and I intend to use the rain in many rooms, so I need to be able to turn on and off the rain based on room the player is in. In the Room End Event, I clear the particles; which only deletes them momentarily in the next room and then it resumes. When I tried destroying the particles, the particles stopped but would not start again when I returned the the room that is supposed to have rain. Any ideas on this would be greatly appreciated!!!!

Object Rain Create Event:
Code:
//Rain System
partRain_sys = part_system_create();

//Rain Particle
partRain = part_type_create();
part_type_shape(partRain,pt_shape_line);
part_type_size(partRain,0.2,0.3,0,0);
//part_type_size(partRain,0.1,0.2,0,0); //my adjustment
part_type_color2(partRain,c_teal, c_white);
part_type_alpha2(partRain,.5,.1);
part_type_gravity(partRain,0.1,290);
part_type_speed(partRain,0.5,0.5,0,0);
part_type_direction(partRain,250,330,0,1); //adds wiggle
part_type_orientation(partRain,290,290,0,0,0); //no wiggle
part_type_life(partRain,20,180); //how long it lasts; 140,180 for platformer

//Puddle Particle
partPuddle = part_type_create();
part_type_shape(partPuddle,pt_shape_circle);
part_type_size(partPuddle,0.5,0.8,.01,0);
part_type_scale(partPuddle,.5,.1); //creates oval that gets bigger and squishes out
part_type_color1(partPuddle,c_silver);
part_type_alpha2(partPuddle,.4,0);
part_type_speed(partPuddle,0,0,0,0);
part_type_direction(partPuddle,9,0,0,1); 
part_type_gravity(partPuddle,0,270);
part_type_life(partPuddle,50,60); //how long it lasts

//Set Sequence
part_type_death(partRain,1,partPuddle); //can create more puddles by increasing number; or -5 means one in five chance of creating puddle

//Create Emitter
partRain_emit = part_emitter_create(partRain_sys);
part_emitter_region(partRain_sys,partRain_emit,0,1920,0,0,ps_shape_line,ps_distr_linear);
part_emitter_stream(partRain_sys,partRain_emit,partRain,5);

//Advance System - makes rain start in middle and not at top
repeat(room_speed* 3)  { //3 seconds into system
    part_system_update(partRain_sys);   
}
Room End Event:
Code:
part_particles_clear(partRain);
part_particles_clear(partPuddle);

Edit: So I changed the Room End Event to include the below code instead; and then had the player object create the rain object in the correct rooms if it didn't alreayd exists. This seems to work. Anyone see any issues with memory leaks, etc with this?

Code:
part_type_destroy(partRain);
part_type_destroy(partPuddle);
part_emitter_destroy(partRain_sys,partRain_emit);
part_system_destroy(partRain_sys);

instance_destroy();
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Pre-edit:
You're destroying the particles, but not the entity that spawns them (the emitter). These are not automatically destroyed upon room change.

Post-edit:
You are now destroying the emitter. As long as you destroy every dynamic resource you created, there won't be memory leaks, which seems to be the case here.

You may want to just put an instance of the rain controller object in the corresponding rooms rather than spawning them through the player. Saves you the trouble of having to hard-code which rooms to spawn it in.
 

T2008

Member
Thanks for the response.! If I do not put it in the player object, when I return to the room, there is no rain because the rain object got destroyed at the room end event when I left. Is there another way to achieve this?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Unless your room is persistent, all instances that were placed in it via the room editor will be recreated the next time you enter the room. Destroying instances that were placed in rooms is not a permanent action unless you make it permanent by making the room persistent. If that is the case, don't destroy that instance in the Room End event.
 

T2008

Member
Thanks! My room is persistent, so I guess I have to create it again in the player object else it will be permanently destroyed and rain won't be there when player returns.

Also, not sure if this needs to be different thread, but I've created a fog particle system, and I wanted the particles to appear immediately. I added the below code but that didn't make them appear immediately. How would I get them to start immediately so that room is foggy when player enters?

Code:
//Give Particles Headstart
repeat(200)  {  
    part_system_update(particle_sys_fog1);    
}
 

TsukaYuriko

☄️
Forum Staff
Moderator
That's the correct way to do it. If this has no effect, make sure that you are creating particles before this code runs as particles created afterwards will not be affected. If you're using emitters, make sure that you not only create them but also set them to stream particles before this code runs. You may also have to increase the number of repeats depending on the particles' life span and animation cycle for changes to be more or less noticeable.
 

T2008

Member
Thanks, for some reason, this code doesn't work to create particles immediately. I placed the particle creation before it and it still didn't work. Can't understand why.
 

TsukaYuriko

☄️
Forum Staff
Moderator
This seems to be about code unrelated to the one in the opening post, so if you post the code relevant to that particle system, maybe a second pair of eyes will be able to spot what's going wrong. :)
 

T2008

Member
Thanks. I really appreciate your trying to help. Here's the code:

Create Event
Code:
time = 30; 
alarm[0] = time;

particle_sys_fog1 = part_system_create();

part_fog1 = part_type_create();

part_type_shape(part_fog1,pt_shape_cloud);
part_type_size(part_fog1,4,4,0,0); //1,1,0,0
part_type_color3(part_fog1,c_teal,c_aqua,c_green); //i added
part_type_direction(part_fog1,180,180,0,0); //going to left min, max
part_type_speed(part_fog1,.01,.02,0,0);
part_type_alpha3(part_fog1,0.02,.05,0.2);  //0.02,0.05,0.02)
part_type_life(part_fog1,380,1000);

//Create Fog Near Where Player Starts
//LAB1
if (room = rm_lab1_rm1) {
    if (part_particles_count(part_fog1) < 350) {
        repeat(20) {
            var random_x = random_range(1200, 1300);  
            var random_y = random_range(700,900);
            part_particles_create(particle_sys_fog1,random_x,random_y,part_fog1,10); //last is number of them
        }
    }
}

//Give Particles Headstart
repeat(5000)  {  
    part_system_update(particle_sys_fog1);    
}
Alarm Event
Code:
alarm_set(0,time);

//LAB1
if (room = rm_lab1_rm1) {
    if (part_particles_count(part_fog1) < 200) {
        repeat(20) {
            var random_y = random_range(350,1080);
            var random_x = random_range(850,1350);
            part_particles_create(particle_sys_fog1,random_x,random_y,part_fog1,1); //last is number of them
        }
    }
}
 

TsukaYuriko

☄️
Forum Staff
Moderator
Your particles have a max life span of 1000 but you are advancing the particle system by 5000 frames - that is sure to kill off all particles, and since none of them respawn until the Alarm event fires, you'll have no particles after the fast-forward.

Maybe try a lower number and use an emitter rather than spawning particles in bursts? Otherwise, you'll have sudden spurts of particle spawns potentially followed by longer (not that 30 frames is particularly long, but hey) periods of no particles being spawned, which could make the effect look a bit uneven. With an emitter constantly streaming particles, you'll have an even distribution of particles created over time.
 

T2008

Member
I tried turning into emitter but it didn't work. Anything wrong below?

Code:
time = 30; 
alarm[0] = time;

particle_sys_fog1 = part_system_create();

part_fog1 = part_type_create();

part_type_shape(part_fog1,pt_shape_cloud);
part_type_size(part_fog1,4,4,0,0); //1,1,0,0
part_type_color3(part_fog1,c_teal,c_aqua,c_green); //i added
part_type_direction(part_fog1,180,180,0,0); //going to left min, max
part_type_speed(part_fog1,.01,.02,0,0);
part_type_alpha3(part_fog1,0.02,.05,0.2);  //0.02,0.05,0.02)
part_type_life(part_fog1,380,1000);

//Create Emitter
part_fog1_emit = part_emitter_create(particle_sys_fog1);
part_emitter_region(particle_sys_fog1,part_fog1_emit,random_range(1200,1300),random_range(700,900),0,0,ps_shape_ellipse,ps_distr_linear);
part_emitter_stream(particle_sys_fog1,part_fog1_emit,part_fog1,120);

//Give Particles Headstart
repeat(100)  {  
    part_system_update(particle_sys_fog1);    
}
 

TsukaYuriko

☄️
Forum Staff
Moderator
Works fine on my end. Test this code in an empty project. If it works there but doesn't work in your main project, the problem lies elsewhere.

You defined the minimum and maximum x of the emitter region as random ranges. Is this intentional? As in, is it intentional that you defined the boundaries of the random particle spawn region as random coordinates themselves?
Is it also intentional that the particles only spawn at y coordinate 0?
 

T2008

Member
Thanks. My coordinates turned out to be wrong but even when fixing that, the particles looked bad using the emitter. It's strange that there is a delay still in the particles showing up. I will try your suggestion when I have time about using empty project. Thanks again for your help. I really appreciate it.
 
Top