This function creates a new particle system on a given layer and returns its unique index number.
You give the unique layer ID as returned by the function layer_create or the name of the layer to use as a string - for example "instance_layer" - and then flag the system as being persistent or not.
Optionally you can provide a Particle System Asset created using The Particle System Editor. Doing so will create the system defined in that asset, with all of its emitters.
A system not flagged as persistent is automatically destroyed at the end of the room it was created in (this is the same as if you had called the function part_system_destroy and will also destroy any emitters associated with the system). However, when flagged as persistent, the system will be carried to the next room when the room is changed, and if the following room does not have a layer with the same name or depth as the one assigned, then a new layer will be created for the system that is persisting across the rooms, and it will be named the same as the original layer. When changing rooms, if there is another layer in the following rooms with the same name, then the persisted instance will be assigned to the layer with that name regardless of the depth of the layer. Finally, if a persisted system moves to a room with a layer at the same depth as the layer the system was created on, it will not be assigned to this layer, but instead a new layer will be created at the same depth (with the same name as the original layer).
IMPORTANT If you flag the particle system as persistent, then it (and any emitters assigned to it) will need to be cleaned up manually using the appropriate destroy functions when not in use, otherwise you risk a memory leak that will negatively impact your final game.
part_system_create_layer(layer_id, persistent, [partsys]);
Argument | Type | Description |
---|---|---|
layer | String or Layer | The layer ID (or name) to assign the particle system to (can be any layer type) |
persistent | Boolean | Flag the particle system as persistent (set to true) or not (set to false) |
partsys | Particle System Asset | OPTIONAL The particle system asset to create an instance of |
global.p_sys = part_system_create_layer("effects_layer", true, ps_Explosion);
The above code will create a new particle system on the given layer from the ps_Explosion asset, and flag it as persisting over subsequent rooms. The ID for the particle system is stored in a global scope variable p_sys for future reference.