• 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!

Legacy GM [SOLVED] Change particle colours with a button press

A

AtomicToilet

Guest
Howdy folks.

I've got it so the player can switch states when he presses 1, 2, 3 or 4 which changes the sprite colour and attack animation. That's all hunky dory. What I've now done is attach a particle system to the player object (so it leaves a trail behind them), which again works fine.

However, when the player changes states the particles remain one colour - I'd like to have it so it also changes colour (eg 1 = blue, 2 = green, etc). I thought adding a variable (RexColour) would work, with this added in each state script (eg RexColour = c_blue), so that once the states change the particle system then references the new variable details.

Except this variable is only referenced if I put it in the same Create Event as the particle system (otherwise it can't find the variable; it also still ignores the new variable reference when states/scripts are then changed). I also tried adding RexColour into the button press events but the variable's ignored then as well).

Basically, the game only seems to reference the RexColour variable in the player object Create Event.

What on earth am I doing wrong? Cheers for any help! If I should paste any other code, let me know :)
--------------------------------------------
Here's the object create code:

Code:
state = scr_rex_invincible; //Player (Rex) starts off invincible then presses 1 - 4 to change states
RexColour = c_white;

//particle system
partFairyDust_sys = part_system_create();

//Particle
partFairyDust = part_type_create();
part_type_size(partFairyDust, 1,2,0,0);
part_type_colour1(partFairyDust, RexColour); //RexColour should change depending on state
part_type_alpha2(partFairyDust, 1,0);
part_type_speed(partFairyDust, 0.8, 1, 0,0);
part_type_direction(partFairyDust, 0, 359,0,0);
part_type_blend(partFairyDust, 1);
part_type_life(partFairyDust, room_speed*2, room_speed*4);

//Particle emitter
partFairyDust_emit = part_emitter_create(partFairyDust_sys);

//These tie in to Step code that makes particles only form when player object is moving
old_x = 0;
old_y = 0;
 

Roderick

Member
I'm not super experienced with particles, so I'm not sure if this will work:

Where you're trying to change the RexColor variable, do a full part_type_color1 command instead.

I don't know if you can change particle properties on the fly like that though, so if it doesn't work, you'll have to create four identical particles with different colors, and store the name of the correct particle in a variable, and ise rhat variable when creating your particles .
 
A

Aura

Guest
In order to make particle_type_colour1() change the particle type's colour, you need to call it in the Step event.

Create:
Code:
LastColour = c_white;
RexColour = c_white;
Step:
Code:
if (LastColour != RexColour) {
   particle_type_colour1(partFairyDust, RexColour);
   LastColour = RexColour;
}
 
A

AtomicToilet

Guest
Yes! All I then needed to do was put RexColour in each state script and it works like a charm. Thanks a lot!
 
Top