diff --git a/Materials/Particles/down_particles.tres b/Materials/Particles/down_particles.tres index 3dc88cb..2278767 100644 --- a/Materials/Particles/down_particles.tres +++ b/Materials/Particles/down_particles.tres @@ -6,5 +6,5 @@ emission_shape_offset = Vector3(0, -8, 0) emission_shape = 1 emission_sphere_radius = 7.35 gravity = Vector3(0, -98, 0) -scale_max = 5.0 +scale_max = 2.5 color = Color(0, 0, 0, 1) diff --git a/Materials/Particles/down_particles_bg.tres b/Materials/Particles/down_particles_bg.tres deleted file mode 100644 index ff53954..0000000 --- a/Materials/Particles/down_particles_bg.tres +++ /dev/null @@ -1,11 +0,0 @@ -[gd_resource type="ParticleProcessMaterial" format=3 uid="uid://dhirstigqbwlc"] - -[resource] -particle_flag_disable_z = true -emission_shape_offset = Vector3(0, -8, 0) -emission_shape = 1 -emission_sphere_radius = 7.35 -gravity = Vector3(0, -98, 0) -scale_max = 2.5 -color = Color(0, 0, 0, 0.5137255) -collision_mode = 2 diff --git a/Materials/Particles/up_particles.tres b/Materials/Particles/up_particles.tres index ef7b1a8..bc20c6c 100644 --- a/Materials/Particles/up_particles.tres +++ b/Materials/Particles/up_particles.tres @@ -6,5 +6,5 @@ emission_shape_offset = Vector3(0, -8, 0) emission_shape = 1 emission_sphere_radius = 7.35 gravity = Vector3(0, 98, 0) -scale_max = 2.0 +scale_max = 2.5 color = Color(0, 0, 0, 1) diff --git a/Materials/Particles/up_particles_bg.tres b/Materials/Particles/up_particles_bg.tres deleted file mode 100644 index f040717..0000000 --- a/Materials/Particles/up_particles_bg.tres +++ /dev/null @@ -1,11 +0,0 @@ -[gd_resource type="ParticleProcessMaterial" format=3 uid="uid://ch1r4nhrcpg3s"] - -[resource] -particle_flag_disable_z = true -emission_shape_offset = Vector3(0, -8, 0) -emission_shape = 1 -emission_sphere_radius = 7.35 -gravity = Vector3(0, 98, 0) -scale_max = 2.5 -color = Color(0, 0, 0, 0.5058824) -collision_mode = 2 diff --git a/Scripts/background_particles.gd b/Scripts/background_particles.gd index 31bf185..8de5a59 100644 --- a/Scripts/background_particles.gd +++ b/Scripts/background_particles.gd @@ -1,36 +1,51 @@ extends Node2D -@export var number_of_particles : int +@onready var up_material : ParticleProcessMaterial = load("res://Materials/Particles/up_particles.tres") #The process material for when gravity is upwards. +@onready var down_material : ParticleProcessMaterial = load("res://Materials/Particles/down_particles.tres") #The process material for when gravity is downwards. -var particle_child : GPUParticles2D -var up_material : ParticleProcessMaterial = load("res://Materials/Particles/up_particles_bg.tres") -var down_material : ParticleProcessMaterial = load("res://Materials/Particles/down_particles_bg.tres") +@export var number_of_particles : int #The total number of particles we want emitting. + +var particle_child : GPUParticles2D #The child node that's holding the emitting particles. # Called when the node enters the scene tree for the first time. func _ready() -> void: + #Duplicate the process materials so we have a local copy. + #Done so we don't modify the process material attached to the player particle emitter. up_material = up_material.duplicate() down_material = down_material.duplicate() reloadParticles() func _physics_process(delta: float) -> void: + + #Run reloadParticles() when gravity is changed. if Input.is_action_just_pressed("flip"): print("input detected") reloadParticles() +#Detect gravity, and set the appropriate process material to the GPUParticles2D child node. +#If that child node does not exist, then create it, and then assign the process material. func reloadParticles() -> void: #If the particle node does not already exist, do the initial setup, and add it as a child node. if !has_node("BGParticles"): + + #Create a new GPUParticles2D object. var bgparticle := GPUParticles2D.new() + + #Set number of particles, make them emit by default, make them top level to not follow camera, and set name. bgparticle.amount = number_of_particles bgparticle.emitting = true bgparticle.top_level = true bgparticle.name = "BGParticles" + + #Add our created GPUParticles2D object as a child to this Node. add_child(bgparticle) + + #Set our particle_child variable equal to our newly created child Node so we can modify it later. particle_child = get_node_or_null("BGParticles") - #Set up the material we want to set the particle node to, and set up a screen size variable. + #Set up a termpoary material variable, and set up a screen size variable. var material : ParticleProcessMaterial var size : Vector2 = get_viewport_rect().size @@ -40,8 +55,10 @@ func reloadParticles() -> void: elif al_globals.y_gravity < 0: material = down_material - #Set the emission shape and the size, relative to size of screen. + #Set the emission shape to a box, with an assignable size. material.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX + + #Set the bounds of the emission box equivalent to the current screen size. material.emission_box_extents = Vector3(size.x, size.y, 0) #Set the material of the particle child object to the created material.