Particles going in and out of rooms

I started trying to understand particles and I pretty much was able to understand step by step. Although this may be the case, I (of course) had a small problem. In my game, one room would have a snow particle, when I go into the next one, I don't want to have the snow particle, yet it still is streaming the particles. My object is not persistent in this case, so I don't know why it is carrying over still. Here's my code:

For OBJ_particle_system

Create Event:

//Create the Particle System
global.ps = part_system_create();
em = part_emitter_create(global.ps);

part_emitter_region(global.ps, em, 0, room_width, -16, 0, ps_shape_rectangle, ps_distr_linear);

//Initialize the particles
scr_part_blood_init();
scr_part_snow_init();

Step Event:

part_emitter_stream(global.ps, em, global.pt_snow, 5);

Game End Event:

//Destroys the particle system and type
part_type_destroy(global.pt_snow);
part_type_destroy(global.pt_blood);
part_system_destroy(global.ps);

Script for Snow Particles:

//Initialize our global snow particle
global.pt_snow = part_type_create();
var pt = global.pt_snow;

//Set the settings for the snow particle
part_type_shape(pt, pt_shape_pixel);
part_type_size(pt, 1, 2, 0, 0);
part_type_color1(pt, c_white);
part_type_speed(pt, 2, 3, 0, 0);
part_type_direction(pt, 240, 310, 0, 0);
part_type_life(pt, 400, 400);

Like I said, I have most of the basics down tight, its just making sure that these particles don't carry over to another room that I don't wish to have these particles. If anyone knows how I can do this, please let me know. Thanks.
 
Maybe stop the particle stream as a Room End event?
I tried this and the particles stopped completely, but I was still able to see a little bit of the snow particles in the next room as well as when I go back into the room with the particles, it doesn't seem to come back.
 

Nidoking

Member
I tried this and the particles stopped completely, but I was still able to see a little bit of the snow particles in the next room as well as when I go back into the room with the particles, it doesn't seem to come back.
You're leaking the particle system and particle type if you return to the room, because when you create a new instance, you're overwriting the global variables with a new system and type. It's weird that you made the emitter an instance variable while the system is a global variable. I have no idea whether that causes the issue with your particles not reappearing when you return to the room, but if you're not going to use the particle system globally, then maybe don't make any of it global.

To clear the visible particles, clear the particle system/emitter. Then you'll need to reset the region before using it again.
 
Alright, I sort of got it, I managed to make it so that it doesn't leak anymore into other rooms, I only have one problem now. When I go into another room that has the same particle effect, it takes time before you see the snow fall again, as if the snow disappeared for a brief moment and then came back again. I tried to use exceptions so that is it room specific in a step event but it doesn't seem to change anything. I'm trying to make it so that in certain rooms the particle effect will carry over to the next room but the room before the starting room and the room after the last room with snow will destroy that effect.
 

Nidoking

Member
You could just manually advance the particle system by an appropriate number of steps at room start, so that when you enter a snowy room, the snow is already falling.
 
This kinda sounds noobish, but how would I do that? If it's simple as making the code at something other than step 1 then it didn't seem to work. How would I advance the particle system this way?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Alright, I sort of got it, I managed to make it so that it doesn't leak anymore into other rooms, I only have one problem now. When I go into another room that has the same particle effect, it takes time before you see the snow fall again, as if the snow disappeared for a brief moment and then came back again. I tried to use exceptions so that is it room specific in a step event but it doesn't seem to change anything. I'm trying to make it so that in certain rooms the particle effect will carry over to the next room but the room before the starting room and the room after the last room with snow will destroy that effect.
There's an even easier solution: have the snow particle spawner object create a few hundred (or whatever's appropriate) particles over the starting position of the view when you first load into a room. Just put a for loop in its create event that creates 1 particle at a random position and make sure it repeats just the right amount of times (based on snowfall intensity and room size)
 
H

Hillelgo

Guest
I also have a lot of problems with particles. I actually can't really seem to clear them.

On up key (for in game testing):
Code:
///cleanup

part_emitter_destroy(part_system,first_emitter);
part_particles_clear(part_system);
part_emitter_destroy(part_system,first_emitter);
part_type_destroy(fire);
part_type_destroy(explosion);
part_type_destroy(firework);
part_type_destroy(fountain);
part_system_destroy(part_system);

instance_destroy(id);
But even after this overkill cleanup I still get this in the console, like the emitter is still running:

GML:
part_particles_create :: particle type does not exist!

EDIT Nevermind, it was a copy/paste mistake, everything is fine.
 
Last edited by a moderator:
Top