Parallaxeffect of partcile systems interfear with oher particle systems

Bulltron

Member
Hey,
my problem is to combine two "types" of particle systems in one room.
The first "type" uses emitters and got a parallax effect and is created on an asset-layer.
The second "type" is created by part_particles_create on an instance-layer.

Both systems work as intended, if the other one is not in the room. If they are placed in the same room, the parallax effect is acting up. Which of the system-"types" is affected, depends on which of the systems is created first and how often. Sometimes the second particle "type" suddenly gets a parallax effect. Sometimes the first type looses its parallax effect. If i delete the code-lines for the parallax effect of the "type" one particles, none of the particles have a parallax effect. So somehow the parallax effect makes it from one system to the other. No idea how. It does not make a difference, if the room is the first in the game or not. Multiple times of entering and exiting the room does not make a difference.

Here the exact example with the code i use:

The persistent object A defines all my particle types like this (just one particle as example. The other particle is also defined in this object in basicly ths same way):

game-start-event:

global.particle_PixelShower = part_type_create();
part_type_sprite(global.particle_PixelShower, sPixelShower, 0, 0, false);
part_type_size(global.particle_PixelShower, 1.0, 1.0, 0, 0);
part_type_speed (global.particle_PixelShower, 2, 4, 0, 0)
part_type_direction (global.particle_PixelShower, 270, 270, 0, 0);
part_type_life (global.particle_PixelShower, 1800, 1800);
part_type_alpha1(global.particle_PixelShower, 0.7);

game-end-event:

part_system_clear(global.particle_PixelShower);
part_type_destroy(global.particle_PixelShower);

Object B creates 7 particle systems of the first "type". The following lines show just one of them as an example, because the other systems are basically the same, they just use slightly other particles (all defined in object A) and use other layers:

create-event:

global.particle_system_pix = part_system_create_layer ("Close_Back",false);
global.emitterPixelShower = part_emitter_create(global.particle_system_pix);
part_emitter_region(global.particle_system_pix, global.emitterPixelShower, 0, room_width, 0, 0, ps_shape_rectangle, ps_distr_linear);
part_emitter_stream(global.particle_system_pix, global.emitterPixelShower, global.particle_PixelShower, 1000);

step-event (updating the particle, so the background is already covert in particles when the room starts):

if (once = 1)
{
repeat(600) {part_system_update(global.particle_PixelShower);}
once--;
}

end-step-event (here goes the parallax effect):

if (instance_exists (oCamera))
{
part_system_position(global.particle_PixelShower, oCamera.x /10, 0);
}

clean-up-event:


part_system_destroy(global.particle_system_pix);
part_emitter_destroy(global.particle_system_pix, global.emitterPixelShower);

Obect C creates the second "type" of particles in its x and y position

create-event:

global.particle_system_lvlTester = part_system_create_layer ("Enemy", false);

step-event:

part_particles_create(global.particle_system_lvlTester, x, y, global.particle_leveltester, 3);

clean-up-event:

part_system_destroy (particle_system_lvlTester);



I banged my head against this problem for almost 20 hours now. You would make my day, if you could help, so thanks in advance.
 

Nidoking

Member
You're not entirely consistent with your use of "global". Why is anything global anyway? If you have a persistent instance, maybe try making everything an instance variable of that instance, or better yet, the instance that's creating the particular things you're making. The chance that somewhere in the part you haven't posted, you're reusing the same global variable twice, is pretty high.
 

Bulltron

Member
Somehow i deleted the "global" in the last clen-up-event in obect C, but only in this post, not in my code. I use global that much, because i thougt, it has to be like this (all the tutorials i watched did it like this). I checked my code about 4 times for typos, so i am pretty sure that is not the mistake. Furthermore, there are more partilce-systems like this in my game. The error occures always between the two "types" of particles. Even if i made a typo somewhere in the code, i doubt, i made the exact same mistace four times.
 

Nidoking

Member
You only need to make it once for it to apply to the wrong thing. If you use a separate instance for each system/emitter, and you don't use any global variables, then you can guarantee that you're not mixing up the same thing between different instances. Does the problem still happen when you do that?
 

Bulltron

Member
I created a new object for each system and it actually worked in the first room. But if i leave the room and come backthe parallax is gone. Even if i put only one object with one particle-system in the room. Maybe i made a mistake somewhere else. Maybe something to do with the room-transition?

The following code is the exact code for the only object in the room with a particle system. Nothing else in the room has anything to do with particles. If i start in this room with the object, the parallax works, but if i leave and come back, it won't.


Create:

particle_system_pix3 = part_system_create_layer ("Far_Back",false);

particle_PixelShower_3 = part_type_create();
part_type_sprite(particle_PixelShower_3, sPixelShower2, 0, 0, false);
part_type_size(particle_PixelShower_3, 0.65, 0.75, 0, 0);
part_type_speed (particle_PixelShower_3, 2, 4, 0, 0)
part_type_direction (particle_PixelShower_3, 270, 270, 0, 0);
part_type_life (particle_PixelShower_3, 1800, 1800);
part_type_alpha1(particle_PixelShower_3, 0.7);

emitterPixelShower_3 = part_emitter_create(particle_system_pix3);
part_emitter_region(particle_system_pix3, emitterPixelShower_3, 0, room_width, 0, 0, ps_shape_rectangle, ps_distr_linear);
part_emitter_stream(particle_system_pix3, emitterPixelShower_3, particle_PixelShower_3, 100);

End Step:

if (instance_exists (oCamera))
{
part_system_position(particle_PixelShower_3, oCamera.x /4, 0);
}

Clean Up:

part_system_destroy(particle_system_pix3);
part_emitter_destroy(particle_system_pix3, emitterPixelShower_3);
 

Nidoking

Member
Is the room persistent? Is the object persistent? The particle system isn't, so if you leave the room, you need to recreate it when you come back.
 

Bulltron

Member
Neither the object or the room is persistent, so the particle system should be created every time i enter the room
 

Nidoking

Member
Might be a good idea to use the debugger to check that. Put a debug message or a breakpoint where the particle system is created and make sure it happens each time you enter the room.
 

Bulltron

Member
It seems to be working now. I changed the sequence of the clean up and i only used global for the particle itself, not for the emitter or the system. Thanks for the help, Nidoking :)
 
Top