1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 need help Understanding Particles

Discussion in 'Programming' started by ragingdemonz, Sep 2, 2017.

  1. ragingdemonz

    ragingdemonz Member

    Joined:
    Jun 28, 2016
    Posts:
    287
    Okay so right now im starting to get into the particle system. From what i read and understand i should probably make the particle system global to use throughout the game. From alot of tutorials that i have followed online they all put them in the create event of some sorta controller object.

    So lets say if i want to use the particles for multiple objects and i want the animation of the particles to start from the beginning every time it is created. Do i create the object multiple times?? How do i stop creating the particles after a certain amount lets say i want to create like 100 from an emitter do i just set up some sorta check like
    If part >=30{destroy particle system}

    i guess i just want to know how to create some particle effects universally. Also how do i free up the particles from memory after switching to another room and such? Do the particles themselves that are created from an emitter free itself from memory after their lifespan is over?

    should i just create a persistent object ??
     
    Last edited: Sep 2, 2017
  2. Perseus

    Perseus Not Ragarnak Forum Staff Moderator

    Joined:
    Dec 29, 2016
    Posts:
    953
    No, as you mentioned, you can use a single instance of a controller object to create the paticle system(s) / emitter(s) / type(s) and assign their indexes to global variables (preferably only once at the start of your game to avoid clutter of useless code and instances), so that they can be accessed everywhere in your game after creation. It might also be worthwhile to learn the difference between objects and instances while we're at it.

    There is a function called part_particles_count() that returns the number of particles in a system. You could check if it returns a value smaller than 100 before emitting more particles to the system. Another option is to use a variable which is to get incremented every time a particle is created. It would be a more viable option if you're concerned about the execution cost of part_particles_count() and / or there are particles of multiple types in the same system but you want data of only one.

    No, they do not clear up themselves when the room changes. You need to do it manually via part_particles_clear().
     
  3. ragingdemonz

    ragingdemonz Member

    Joined:
    Jun 28, 2016
    Posts:
    287
    @Ragarnak
    Thanks for the response, i made a little Sample project. This is how i have it setup so far

    Obj_init:
    Code:
    Persistent = true
    global.p1_sys = part_system_create();
    part1_type_scr(); //Calls the script and creates the type in global.type1
    part2_type_scr();
    ///Game End
    part_type_destroy(global.part1);
    part_type_destroy(global.part2);
    part_system_destroy(global.p1_sys);

    part1_type_scr();
    Code:
    ///Init out global emitter particles
    global.part1 =part_type_create();
    
    var p1 = global.part1
    var col=make_colour_rgb(100,149,237)
    
    part_type_shape(p1,pt_shape_spark);
    part_type_scale(p1,1,1); //Changes the shape
    part_type_size(p1,0.1,0.4,-0.005,0);
    part_type_color2(p1,col,c_white);
    part_type_alpha2(p1,1,0.5);
    
    part_type_speed(p1,0.1,0.5,0.01,0);
    part_type_direction(p1,1,375,0,0);
    part_type_gravity(p1,0.02,90);
    
    
    part_type_life(p1,room_speed*2,room_speed*3);
    part_type_blend(p1,1)

    obj_particle
    Code:
    ///Create
    em=part_emitter_create(global.p1_sys);
    part_emitter_region(global.p1_sys,em,x-40,x+40,y-40,y+40,ps_shape_ellipse,ps_distr_gaussian)
    part_emitter_stream(global.p1_sys,em,global.part1,1)
    
    //Code for Destroy, Room End and game end
    part_emitter_clear(global.p1_sys, em);
    part_emitter_destroy(global.p1_sys,em);
    

    is this how its done?
     
  4. Jax_the_grey_cat

    Jax_the_grey_cat Member

    Joined:
    Jul 12, 2016
    Posts:
    24
    Hello!

    I do it this way, for example, a small particle system I use for some fire

    I have a small sprite with the fire particles obviously, and this is the code I use in the object that generates the fire.

    Create event:

    ///Particles
    //Part system
    partFire_sys = part_system_create();
    part_system_depth(partDestroy_sys, -bbox_bottom);

    //Fire particle
    partFire = part_type_create();
    part_type_sprite(partFire, spr_partSmoke5x5, 0, 0, 1);
    part_type_size(partFire, 0.4, 0.5, 0, 0);
    part_type_colour2(partFire,c_red,c_orange);
    part_type_alpha3(partFire,0.5,1,0);
    part_type_speed(partFire,0.1,0.2,0,0);
    part_type_direction(partFire,85,95,0,10);
    part_type_orientation(partFire,0,359,0,0,0);
    part_type_life(partFire,20,40);

    End step event:
    ///Movement particles
    if random(1)<= 0.75
    {
    repeat(1)
    {
    part_particles_create(partFire_sys, random_range(x-1,x+3), random_range(y-7,y-5), partFire, 1);
    }
    }

    I like to use the random, and repeat, to play around with different frequencies of particle spamming.

    Also answering to your first post, personally, I do not use nothing related to particles in my controller object. Every object I have that uses particles, has the first script in the create event. And the second in step. I found it much easier to personalize the functionality of each object and it's particles.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice