MeltingCat
Member
Hi!
I'm trying to fix an error occurring in a particle system I created. The system is bound to an object and is destroyed on room end. It is a particle system to create a rain effect with a parallax motion.
The issue is this: it works fine when I first enter the room. It keeps working fine if I go into another room containing the rain object. If I enter a room without rain and go back to the one that had rain on it, the depth is underneath the player (not where I want), and the positioning is also slightly off. The rooms are persistent, but the particle system and emitters are being destroyed on every room end and recreated on room start. The object and system is not referenced in any other object.
Any ideas are appreciated!
Here is the code:
//probably unrelated, but it's there. creates additional splash particles on the ground.
Thank you for reading!
I'm trying to fix an error occurring in a particle system I created. The system is bound to an object and is destroyed on room end. It is a particle system to create a rain effect with a parallax motion.
The issue is this: it works fine when I first enter the room. It keeps working fine if I go into another room containing the rain object. If I enter a room without rain and go back to the one that had rain on it, the depth is underneath the player (not where I want), and the positioning is also slightly off. The rooms are persistent, but the particle system and emitters are being destroyed on every room end and recreated on room start. The object and system is not referenced in any other object.
Any ideas are appreciated!
Here is the code:
GML:
//Create event
RainSystem = noone
RainEmitter = noone
RainStrength = 5
RainAngle = -20
MoveRate = -0.23
// Raindrop
Rain = part_type_create();
part_type_sprite(Rain, s_Rain, false, false, false);
part_type_size(Rain, 1.7, 2.0, -0.05, 0)//0.7, 1.1, 0, 0);
part_type_scale(Rain, 1, 1.2);
part_type_orientation(Rain, RainAngle+90, RainAngle+90, 0, 0, 0);
part_type_color3(Rain, c_white, c_white, c_white);
part_type_alpha2(Rain, 0.08, 0.3)//0.2, 0.2);
part_type_blend(Rain, true);
part_type_life(Rain, 50, 60);
part_type_speed(Rain, 9, 11, 0, 0)//10, 13, 0, 0);
part_type_direction(Rain, 270+RainAngle , 270+RainAngle, 0, 0);
alarm[0] = 2 //initializing stuff
GML:
//alarm[0]
/// @description init
Width = o_Camera.Width
Height = o_Camera.Height
RainSystem = part_system_create()
if layer_exists("Rain") {
depth = layer_get_depth("Rain")
part_system_layer(RainSystem, "Rain")
}
//I have tried all sorts of things here, including using part_system_create_layer and part_system_depth
if ! part_emitter_exists(RainSystem, RainEmitter) {
RainEmitter = part_emitter_create(RainSystem)
}
part_emitter_stream(RainSystem, RainEmitter, Rain, RainStrength)
GML:
//Room start
alarm[0] = 2
GML:
//Room end
if part_emitter_exists(RainSystem, RainEmitter) {
part_emitter_destroy(RainSystem, RainEmitter)
}
if part_system_exists(RainSystem) {
part_system_clear(RainSystem)
part_system_destroy(RainSystem)
}
GML:
//step event
var _CamX = o_Camera.x
var _CamY = o_Camera.y
x = _CamX - (( _CamX ) * MoveRate)
y = _CamY - (( _CamY ) * MoveRate)
if part_system_exists(RainSystem) {
part_emitter_region(RainSystem, RainEmitter, x - (Width/2), x + (Width/2) + 150, y - (Height/2) - 100, y - 40, ps_shape_rectangle, ps_distr_linear )
part_system_position(RainSystem, _CamX* MoveRate, _CamY* MoveRate)
}
//probably unrelated, but it's there. creates additional splash particles on the ground.
GML:
if RainStrength < 3 {
var _Rain = RainStrength/3
if Chance(_Rain) { //3
var _Partx1 = irandom_range(_CamX - (Width/2), _CamX + (Width/2) )
var _Party1 = irandom_range(_CamY - (Height/2), _CamY + (Height/2) )
part_particles_create(global.PlayerPSystem, _Partx1, _Party1, global.Splash, choose(2, 3, 3, 4));
if part_system_exists(global.WaterSystem) {
part_particles_create(global.WaterSystem, _Partx1, _Party1, global.WaterSplash, 1)
}
}
} else {
repeat round(RainStrength/3) { //3
var _Partx1 = irandom_range(_CamX - (Width/2), _CamX + (Width/2) )
var _Party1 = irandom_range(_CamY - (Height/2), _CamY + (Height/2) )
part_particles_create(global.PlayerPSystem, _Partx1, _Party1, global.Splash, choose(2, 3, 3, 4));
if part_system_exists(global.WaterSystem) {
part_particles_create(global.WaterSystem, _Partx1, _Party1, global.WaterSplash, 1)
}
}
}
Thank you for reading!