Additional commenting in background_particles.gd, removal of duplicate background particle process materials due to the usage of duplicate().
This commit is contained in:
parent
c988769e98
commit
f12885ba4c
5 changed files with 25 additions and 30 deletions
|
|
@ -6,5 +6,5 @@ emission_shape_offset = Vector3(0, -8, 0)
|
||||||
emission_shape = 1
|
emission_shape = 1
|
||||||
emission_sphere_radius = 7.35
|
emission_sphere_radius = 7.35
|
||||||
gravity = Vector3(0, -98, 0)
|
gravity = Vector3(0, -98, 0)
|
||||||
scale_max = 5.0
|
scale_max = 2.5
|
||||||
color = Color(0, 0, 0, 1)
|
color = Color(0, 0, 0, 1)
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -6,5 +6,5 @@ emission_shape_offset = Vector3(0, -8, 0)
|
||||||
emission_shape = 1
|
emission_shape = 1
|
||||||
emission_sphere_radius = 7.35
|
emission_sphere_radius = 7.35
|
||||||
gravity = Vector3(0, 98, 0)
|
gravity = Vector3(0, 98, 0)
|
||||||
scale_max = 2.0
|
scale_max = 2.5
|
||||||
color = Color(0, 0, 0, 1)
|
color = Color(0, 0, 0, 1)
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -1,36 +1,51 @@
|
||||||
extends Node2D
|
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
|
@export var number_of_particles : int #The total number of particles we want emitting.
|
||||||
var up_material : ParticleProcessMaterial = load("res://Materials/Particles/up_particles_bg.tres")
|
|
||||||
var down_material : ParticleProcessMaterial = load("res://Materials/Particles/down_particles_bg.tres")
|
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.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
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()
|
up_material = up_material.duplicate()
|
||||||
down_material = down_material.duplicate()
|
down_material = down_material.duplicate()
|
||||||
reloadParticles()
|
reloadParticles()
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
|
||||||
|
#Run reloadParticles() when gravity is changed.
|
||||||
if Input.is_action_just_pressed("flip"):
|
if Input.is_action_just_pressed("flip"):
|
||||||
print("input detected")
|
print("input detected")
|
||||||
reloadParticles()
|
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:
|
func reloadParticles() -> void:
|
||||||
|
|
||||||
#If the particle node does not already exist, do the initial setup, and add it as a child node.
|
#If the particle node does not already exist, do the initial setup, and add it as a child node.
|
||||||
if !has_node("BGParticles"):
|
if !has_node("BGParticles"):
|
||||||
|
|
||||||
|
#Create a new GPUParticles2D object.
|
||||||
var bgparticle := GPUParticles2D.new()
|
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.amount = number_of_particles
|
||||||
bgparticle.emitting = true
|
bgparticle.emitting = true
|
||||||
bgparticle.top_level = true
|
bgparticle.top_level = true
|
||||||
bgparticle.name = "BGParticles"
|
bgparticle.name = "BGParticles"
|
||||||
|
|
||||||
|
#Add our created GPUParticles2D object as a child to this Node.
|
||||||
add_child(bgparticle)
|
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")
|
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 material : ParticleProcessMaterial
|
||||||
var size : Vector2 = get_viewport_rect().size
|
var size : Vector2 = get_viewport_rect().size
|
||||||
|
|
||||||
|
|
@ -40,8 +55,10 @@ func reloadParticles() -> void:
|
||||||
elif al_globals.y_gravity < 0:
|
elif al_globals.y_gravity < 0:
|
||||||
material = down_material
|
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
|
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)
|
material.emission_box_extents = Vector3(size.x, size.y, 0)
|
||||||
|
|
||||||
#Set the material of the particle child object to the created material.
|
#Set the material of the particle child object to the created material.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue