Destroying Particle Emitters created by a Script?

A

Anomaly

Guest
Hi guys,

I've been decorating my levels with weather made by particles.. snow rain etc..

I have a script "Weather" that gets executed in an object's create event, at the beginning of the room creation.
in the script "Weather" that's called... is a switch / case flow with particle creations in each case.

After the script creates the emitter, I need to destroy the emitter like I've needed to do in other particle setups, so it doesn't remake itself it each step, right?

When using the emitters in an object, I'd just use the destroy event, but scripts don't have that option.
I put the destroy code in the bottom of the weather emitter script but i think it destroys them faster then it had time to make any particles.

Maybe I'm not calling their specific location properly?

Code:
    // DESTROY EMITTERS
part_system_destroy(snow);
part_system_destroy(rain);
part_system_destroy(flare);
part_system_destroy(cloud);
should it be like..
Code:
something_else.part_system_destroy(snow);
???

ALSO...
in this situation, since they're only initialized by the script once at room creation, ...
Do i NEED to destroy them?

I had them destroyed at "room end" and that stopped them from persisting in other rooms, but i don't know if it's good enough, I just don't want my particle load to crowd up while that room is played...and my memory, crash the game etc... I've had that happen a lot before using the destroy code.

Any tips?

THANKS!!
 

Slyddar

Member
You need to destroy them when you have finished with them, as in when they have emitted the amount of particles you require. The emitter is just where the particles will come from. You still need to stream, burst or just create some particles from that emitter. I believe you are correct in thinking that destroying them in the same script which creates them is too soon and they are not getting a chance to emit.
If you only want them to show a few particles, then you can just use a burst. Then either destroy the emitter and particle system at room end, or if you don't need it after the burst destroy it with an alarm if it's creating problems for you, i.e you have too many in the room.
Also in regards to referencing them, the particle systems will belong to the object which you created them in, or called the script from. If created in o_partsys, and you want to destroy them from another object, you can reference them with part_system_destroy(o_partsys.snow);
 
A

Anomaly

Guest
You need to destroy them when you have finished with them, as in when they have emitted the amount of particles you require. The emitter is just where the particles will come from. You still need to stream, burst or just create some particles from that emitter. I believe you are correct in thinking that destroying them in the same script which creates them is too soon and they are not getting a chance to emit.
If you only want them to show a few particles, then you can just use a burst. Then either destroy the emitter and particle system at room end, or if you don't need it after the burst destroy it with an alarm if it's creating problems for you, i.e you have too many in the room.
Also in regards to referencing them, the particle systems will belong to the object which you created them in, or called the script from. If created in o_partsys, and you want to destroy them from another object, you can reference them with part_system_destroy(o_partsys.snow);
thanks for responding,
well in this case they all need to constantly stream because they're weather, snow, rain etc...
and they die after their "life" time has been reached right?
 
A

Anomaly

Guest
yeah the room is crashing now because of my fog cloud emitter not being destroyed...
(got some nice ground fog rolling in now tho!)...

so I'm definitely going to have to destroy them in the room ... before the room ends....
the problem remains!...

also a side question regarding the snowflakes, clouds i'm making...
s there any way to actually use your own custom sprites in particles?

THANKS!
 
Last edited by a moderator:

NightFrost

Member
For custom particles, you must first define them with particle commands. For example:
Code:
// In create event as you only need to do this once
Part_Snowflake = part_type_create();
part_type_sprite(Part_Snowflake, spr_snowflake, false, false, false);
See the part_type_* commands for more information on defining their speed, motion etc.
Then in the emitter command you must refer to the custom particle:
Code:
// Assuming we have particle system, emitter regions etc defined and ready
part_emitter_burst(Snow_System, Snow_Emitter, Part_Snowflake);
 

Slyddar

Member
Ensure you have fully read the help files on particles to understand how to use them. Sounds like you are continually creating the particles every step. The steps should be as below.

In an objects create event, say o_part. I'll use GMS2 as the example, not sure if you are on 1.4x
1. Define the particle system.
2. Define a particle type that is going to be emitted.
3. Then define the properties of that particle. You can use something like Particle Designer 2.5 to see what the particles will look like, then export the tab and paste that part here.
4. Define an emitter if needed. You can create the particles with either an emitter if you want to stream or burst to an area/region, or just by part_particles_create() for a single spot.
5. Define a variable for the timing you require.
Code:
partsys1 = part_system_create_layer("particles", true);
part_fog = part_type_create()
//define properties here
part_fog_emitt = part_emitter_create(partsys1);
part_emitter_region(partsys1,part_fog_emitt,0,room_width,0,room_height,ps_shape_rectangle,1);     //this will create fog over the whole room
create_fog = true;
Now in the step event of o_part you can create the particles:
Code:
if create_fog {
  //burst 100 particles over the region defined.
  part_emitter_burst(partsys1,part_fog_emitt,part_fog,100);   
  //how long until the next burst.  It will depend on the life of your defined particles as to how often you need to burst them.
  alarm[0] = room_speed*2;
  create_fog = false;
}
Then create an alarm[0] with the code
Code:
create_fog = true
Now the fog will only be created every 2 seconds. When the room ends or you no longer want fog you can add a room_end event to o_part with:
Code:
part_system_destroy(partsys1);
part_type_destroy(part_fog);
part_emitter_destroy(partsys1,part_fog_emitt);
 
Last edited:
A

Anomaly

Guest
Thank you guys so much for the help,
Very much learning happening because of you.
...and yes the manual has been kind to me once I became more familiar with its navigation.

One thing, I used the part_type_sprite action and all I get is squares.
I have just a black squiggle drawing w transparent background.
Ive heard custom sprite alpha background can be testy...

Your experience on this?
 

Slyddar

Member
It works fine with transparency. Just did a quick test in GM2 with a new sprite, deleting the part_type_shape line and using the code
Code:
part_type_sprite(part_type,sprite1,0,0,0)
and it worked perfectly.
 
Top