fuzzyworld

godot-shooter / commit

Added parallax starfield.

2ef72487cbb63ced40be3469a8a29e964db4d516 · Pavel Safronov · 2023-11-01 12:02:28 -0700 · parents e84784b2d870

Added parallax starfield.
 Player.tscn    | 10 ++++------
 StarField.tscn | 36 ++++++++++++++++++++++++++++++++++++
 World.tscn     | 21 ++++++++++++++++++++-
 3 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/Player.tscn b/Player.tscn
index fce8ffb..ba55048 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -66,16 +66,14 @@ text = "Restart"
 current = true
 
 [node name="CanvasLayer2" type="CanvasLayer" parent="."]
+visible = false
 
 [node name="Background" type="ColorRect" parent="CanvasLayer2"]
-visible = false
 anchor_right = 1.0
 anchor_bottom = 1.0
-margin_left = -509.0
-margin_top = -298.0
-margin_right = -509.0
-margin_bottom = -298.0
-color = Color( 0, 0, 0, 1 )
+margin_top = -2.0
+margin_bottom = -2.0
+color = Color( 0.811765, 0, 0, 1 )
 
 [node name="ShotTimer" type="Timer" parent="."]
 
diff --git a/StarField.tscn b/StarField.tscn
new file mode 100644
index 0000000..bb064c6
--- /dev/null
+++ b/StarField.tscn
@@ -0,0 +1,36 @@
+[gd_scene load_steps=7 format=2]
+
+[ext_resource path="res://assets/kenney_simple-space/PNG/Default/star_small.png" type="Texture" id=1]
+
+[sub_resource type="Gradient" id=4]
+
+[sub_resource type="GradientTexture" id=5]
+gradient = SubResource( 4 )
+
+[sub_resource type="Curve" id=1]
+_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.256659, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.490196, 0.297297 ), 0.0, 0.0, 0, 0, Vector2( 0.74092, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
+
+[sub_resource type="CurveTexture" id=2]
+curve = SubResource( 1 )
+
+[sub_resource type="ParticlesMaterial" id=3]
+emission_shape = 2
+emission_box_extents = Vector3( 512, 300, 0 )
+flag_disable_z = true
+gravity = Vector3( 0, 0, 0 )
+angular_velocity = 50.0
+angular_velocity_random = 1.0
+orbit_velocity = 0.0
+orbit_velocity_random = 0.0
+scale_random = 1.0
+scale_curve = SubResource( 2 )
+color_ramp = SubResource( 5 )
+
+[node name="StarField" type="Particles2D"]
+position = Vector2( 512, 300 )
+amount = 200
+lifetime = 10.0
+preprocess = 70.74
+visibility_rect = Rect2( -512, -300, 1024, 600 )
+process_material = SubResource( 3 )
+texture = ExtResource( 1 )
diff --git a/World.tscn b/World.tscn
index 019008f..61ad2d1 100644
--- a/World.tscn
+++ b/World.tscn
@@ -1,15 +1,34 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=6 format=2]
 
 [ext_resource path="res://Enemy.tscn" type="PackedScene" id=1]
 [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
 [ext_resource path="res://HUD.tscn" type="PackedScene" id=3]
 [ext_resource path="res://World.gd" type="Script" id=4]
+[ext_resource path="res://StarField.tscn" type="PackedScene" id=5]
 
 [node name="World" type="Node2D"]
 script = ExtResource( 4 )
 
 [node name="Environment" type="Node2D" parent="."]
 
+[node name="CanvasLayer" type="CanvasLayer" parent="Environment"]
+
+[node name="ParallaxBackground" type="ParallaxBackground" parent="Environment/CanvasLayer"]
+
+[node name="Foreground" type="ParallaxLayer" parent="Environment/CanvasLayer/ParallaxBackground"]
+motion_mirroring = Vector2( 1024, 600 )
+
+[node name="StarField" parent="Environment/CanvasLayer/ParallaxBackground/Foreground" instance=ExtResource( 5 )]
+position = Vector2( 522, 305 )
+
+[node name="Background" type="ParallaxLayer" parent="Environment/CanvasLayer/ParallaxBackground"]
+modulate = Color( 1, 1, 1, 0.501961 )
+motion_scale = Vector2( 0.8, 0.8 )
+motion_mirroring = Vector2( 1024, 600 )
+
+[node name="StarField" parent="Environment/CanvasLayer/ParallaxBackground/Background" instance=ExtResource( 5 )]
+position = Vector2( 522, 305 )
+
 [node name="Player" parent="." groups=["player"] instance=ExtResource( 2 )]
 position = Vector2( 513, 302 )