• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker particles on same object

jonjons

Member
hello
i have an object that makes particles
//create
Code:
sys_worldPart01 = part_system_create(); //-cleanUP-destroy
part_system_layer(sys_worldPart01, layer);
part_system_depth(sys_worldPart01, depth);

part_worldPart01 = part_type_create(); //-cleanUP-destroy

part_type_shape(part_worldPart01, pt_shape_pixel);
part_type_size(part_worldPart01, 1, 2, 0, 0 );
part_type_scale(part_worldPart01, 1, 1);
part_type_color_mix(part_worldPart01, c_white, c_yellow);
part_type_alpha3(part_worldPart01, 0, 1, 0);
part_type_speed(part_worldPart01, 0, 0.2, 0, 0);
part_type_direction(part_worldPart01, 0, 360, 0, 1);
part_type_blend(part_worldPart01, 1);
part_type_life(part_worldPart01, 30, 50);

emit_worldPart01 = part_emitter_create(sys_worldPart01);
//step
Code:
part_emitter_region(sys_worldPart01, emit_worldPart01, x, x+sprite_width, y, y+sprite_height, ps_shape_rectangle, ps_distr_linear);
part_emitter_burst(emit_worldPart01, emit_worldPart01, part_worldPart01, 2);

i wanted to place this object in diferent locations of the room.
but iam not sure if all the particles are going to the frist object placed in the room, or if the particles nullify each other.

Is there a way to use the same obj_particle in deferent locations of the room, without having to create a new object with a new particle sys or emitter ?
 

samspade

Member
hello
i have an object that makes particles
//create
Code:
sys_worldPart01 = part_system_create(); //-cleanUP-destroy
part_system_layer(sys_worldPart01, layer);
part_system_depth(sys_worldPart01, depth);

part_worldPart01 = part_type_create(); //-cleanUP-destroy

part_type_shape(part_worldPart01, pt_shape_pixel);
part_type_size(part_worldPart01, 1, 2, 0, 0 );
part_type_scale(part_worldPart01, 1, 1);
part_type_color_mix(part_worldPart01, c_white, c_yellow);
part_type_alpha3(part_worldPart01, 0, 1, 0);
part_type_speed(part_worldPart01, 0, 0.2, 0, 0);
part_type_direction(part_worldPart01, 0, 360, 0, 1);
part_type_blend(part_worldPart01, 1);
part_type_life(part_worldPart01, 30, 50);

emit_worldPart01 = part_emitter_create(sys_worldPart01);
//step
Code:
part_emitter_region(sys_worldPart01, emit_worldPart01, x, x+sprite_width, y, y+sprite_height, ps_shape_rectangle, ps_distr_linear);
part_emitter_burst(emit_worldPart01, emit_worldPart01, part_worldPart01, 2);

i wanted to place this object in diferent locations of the room.
but iam not sure if all the particles are going to the frist object placed in the room, or if the particles nullify each other.

Is there a way to use the same obj_particle in deferent locations of the room, without having to create a new object with a new particle sys or emitter ?
You can do that, but there really isn't any reason too. The only reason I've found for multiple particle systems is that you want them on multiple layers. Otherwise you only need one system. You also only ever need to define parts once. So you should just create one system in one object. From there you could easily have a separate object that references the system to make particles where it's at and accomplish the same thing.

That said, there's no downside that I know of to creating multiple particle systems except the loss in efficiency that they provide in the first place (assuming you're remembering to destroy them and clean up etc.). So if that doesn't bother you, I don't think it matters.
 

jonjons

Member
In theory its very hard to understand.
There are multiple videos and tutorials about GM particles, and they are all practical identical... This makes it very hard to understand your explanation ? Or to find diferent ways to do it.

If i create an object with a few global vars, for the system, particle, emitter, etc.. The particles will pass from one room to the other, if i destroy the particle system that global is gone and i have to create a new one...

I dont see any way do this, unless make 5 diferent objects, with 5 diferent, system, particle, emitter..etc.. just to spawn the same effect on diferent locations of the room...

1 global system, with multiple objects using that system will simply change the particles locations to the last spawned object.

this almost makes praticles useless ( its just something to look pretty on youtube, smoke/fire following the mouse or something ), not user firendly and something to avoid, if you dont want problems
 
Last edited:

samspade

Member
You're right about there not being many great particle tutorials. That said, they are pretty straight forward once you understand how they work.

A particle system is just a thing - it exists and handles the particles you give it. You can think of it almost like a tiny self contained engine that runs steps and draw events for any particle you give it. Particles are another thing. They are kind of like GM objects that you don't really have any control over. So you have this self contained system that takes its own types of objects and then updates them.

If you want, you can create as many of these as you want, but you slowly lose the efficiency of the whole process and its unnecessary in most case.

Instead:
  • Create one system
  • Create particles for that system
  • Use that system in multiple places
For example in partial pseudo code:

Code:
///obj_ps
///create event

//create the particle system
//create some particles

///clean up event
//destroy the particle system
//destroy all particles

///obj_show_some_particles 
//create event
emit_worldPart01 = part_emitter_create(obj_ps.sys_worldPart01);
part_emitter_region(obj_ps.sys_worldPart01, emit_worldPart01, x, x+sprite_width, y, y+sprite_height, ps_shape_rectangle, ps_distr_linear);
part_emitter_burst(emit_worldPart01, emit_worldPart01, obj_ps.part_worldPart01, 2);

//clean up
//destroy your emittor
I think the above would work, but I'm not sure as I never use emitters. Especially not burst emitters. Instead of burst I would use part_particles_create. That you can easily turn into a script and then the object that shows some particles could be:

Code:
///wherever it makes sense
scr_show_this_type_of_particle(x, y, num);


///scr_show_this_type_of_particle

part_particles_create(obj_ps.sys_worldPart01, argument0, argument1, obj_ps.part_worldPart01, argument2);
 

jonjons

Member
It worked !?! thanks
its very hard to understand because the emitter
Code:
emit_worldPart01 = part_emitter_create(obj_ps.sys_worldPart01);
Is just one, and its being used in multiple instances of the same object... But its not the case for the particle system.

Only a small correction the "part_emitter_burst" needs to be in the step event for the particles to work.

- Ive also moved the "part_type_create()" to the second object "///obj_show_some_particles", this way the same object can make diferent particle shapes, velocites, lifespan, etc, without the need to create a new object.

this seems be the best way for me
///obj_partSYS
///create event
Code:
sys_worldPart01 = part_system_create(); //-cleanUP-destroy
part_system_depth(sys_worldPart01, depth);

//--------------//------//---

///obj_partDeploy
///variable defenitions

minSIZE -- 1 -- real
maxSIZE -- 2 -- real
shape -- pt_shape_pixel -- expression

///create event
Code:
part_worldPart01 = part_type_create(); //-cleanUP-destroy
part_type_shape(part_worldPart01, shape);
part_type_size(part_worldPart01, minSIZE, maxSIZE, 0, 0 );
part_type_scale(part_worldPart01, 1, 1);
part_type_color_mix(part_worldPart01, c_white, c_yellow);
part_type_alpha3(part_worldPart01, 0, 1, 0);
part_type_speed(part_worldPart01, 0, 0.2, 0, 0);
part_type_direction(part_worldPart01, 0, 360, 0, 1);
part_type_blend(part_worldPart01, 1);
part_type_life(part_worldPart01, 30, 50);


emit_worldPart01 = part_emitter_create(obj_partSYS.sys_worldPart01);  //-cleanUP-destroy
part_emitter_region(obj_partSYS.sys_worldPart01, emit_worldPart01, x, x+sprite_width, y, y+sprite_height, ps_shape_rectangle, ps_distr_linear);

///step event
Code:
part_emitter_burst(obj_partSYS.sys_worldPart01, emit_worldPart01, part_worldPart01, 2);
 

NightFrost

Member
I've used burst emitters more than other types, I think. They just need one system and one emitter created, and a particle to use, all set up in some create event. When you want a particle burst, you just set the emitter region where you want and call for a burst. If you need multiple bursts in the same step, you just put the region in a new place and call for another burst. If the region does not need to move, you can set its place in the create event.
 

jonjons

Member
humm.. yeah.. correction in my 1st post
typed the emitter twice:
part_emitter_burst(emit_worldPart01, emit_worldPart01, part_worldPart01, 2);

this way works too, with the same object :oops:
part_emitter_burst(sys_worldPart01, emit_worldPart01, part_worldPart01, 2);
 
Top