Copy fake_explosion_particles.tscn and fake_explosion_particles.gd.
Usage
Instance fake_explosion_particles.tscn and attach fake_explosion_particles.gd as a script.
You can of course use GDScript as well.
# Creata a new node.
var fake_explosion = Node2D.new()
fake_explosion.name = "fake_explosion"
# Attach the script.
fake_explosion.set_script(preload("res://path/to/fake_explosion_particles.gd"))
# Set 'fake_explosion' variables.
fake_explosion.min_particles_number = 5
fake_explosion.max_particles_number = 10
fake_explosion.min_particles_gravity = 20
fake_explosion.max_particles_gravity = 60
fake_explosion.min_particles_velocity = 20
fake_explosion.max_particles_velocity = 60
fake_explosion.min_particles_size = 1
fake_explosion.max_particles_size = 2
# Set its position
fake_explosion.position = Vector2(0, 0)
# This is useful if you want the explosion to be more visible.
fake_explosion.z_index = 1
# Add it to the scene.
get_parent().add_child(fake_explosion, true)
# And then you can explode it whenever you want.
fake_explosion.explode_particles = true
# You can use the name of the group to find all the fake particles nodes more easily.
get_tree().get_nodes_in_group("fake_explosion_particles")
You can change the colors of the particles, but you have to change them inside the script. They are set in particles_colors_with_weights.
The colors of the particles are chosen randomly depending on weights. If you want a color to have more probabilities to be chosen, give it a greater weight.
The minimum and maximum variables values are used to generate random values. If you don't want to use random values, set the minimum and maximum variables values with the same value.
Min particles number
Name
Type
Description
Default
min_particles_number
int
Set the mininum number of the particles.
200
Max particles number
Name
Type
Description
Default
max_particles_number
int
Set the maximum number of the particles.
400
Min particles gravity
Name
Type
Description
Default
min_particles_gravity
float
Set the mininum gravity of the particles.
200.0
Max particles gravity
Name
Type
Description
Default
max_particles_gravity
float
Set the maximum gravity of the particles.
600.0
Min particles velocity
Name
Type
Description
Default
min_particles_velocity
float
Set the mininum initial velocity of the particles.
200.0
Max particles velocity
Name
Type
Description
Default
max_particles_velocity
float
Set the maximum initial velocity of the particles.
600.0
Max particles position X
Name
Type
Description
Default
min_particles_position_x
int
Set the maximum initial X position of the particles.