Commit 7274db7b authored by Nathan Lovato's avatar Nathan Lovato
Browse files

Add infinite foreground

Got an issue with VisibilityNotifier2D: it doesn't work with ParallaxLayer. It
seems to be an engine-side bug: it triggers both the screen_exited and
viewport_exited signals way too early.
parent 479bd8b9
Pipeline #5026 passed with stage
in 4 minutes and 15 seconds
[gd_scene load_steps=14 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://assets/bg.png" type="Texture" id=2]
......@@ -7,42 +7,8 @@
[ext_resource path="res://PillarSpawner/PillarSpawner.tscn" type="PackedScene" id=5]
[ext_resource path="res://Gnu/Gnu.tscn" type="PackedScene" id=6]
[ext_resource path="res://assets/fence.png" type="Texture" id=7]
[ext_resource path="res://assets/particle_hairy.png" type="Texture" id=8]
[sub_resource type="Gradient" id=1]
offsets = PoolRealArray( 0, 0.207407, 0.822222, 1 )
colors = PoolColorArray( 0.403922, 0.2, 0.72549, 0, 0.403922, 0.2, 0.72549, 1, 0.403922, 0.2, 0.72549, 1, 0.403922, 0.2, 0.72549, 0 )
[sub_resource type="GradientTexture" id=2]
gradient = SubResource( 1 )
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0.00428528, 0.0173051 ), 0.0, 1.40242, 0, 0, Vector2( 0.292929, 0.747705 ), 0.956195, 0.956195, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=4]
curve = SubResource( 3 )
[sub_resource type="ParticlesMaterial" id=5]
emission_shape = 2
emission_box_extents = Vector3( 640, 20, 1 )
flag_disable_z = true
spread = 24.68
flatness = 0.32
gravity = Vector3( 0, 40, 0 )
initial_velocity = 57.47
initial_velocity_random = 0.4
angular_velocity = 20.0
angular_velocity_random = 1.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
damping = 25.29
angle = 15.0
angle_random = 1.0
scale = 0.7
scale_random = 0.54
scale_curve = SubResource( 4 )
color_ramp = SubResource( 2 )
hue_variation_random = 1.0
[ext_resource path="res://SpriteSpawner/SpriteSpawner.gd" type="Script" id=8]
[ext_resource path="res://SpriteSpawner/GroundSprite.tscn" type="PackedScene" id=9]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
......@@ -63,6 +29,7 @@ scale = Vector2( 0.66, 1 )
transform = Transform2D( 0.66, 0, 0, 1, 0, 0 )
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground2"]
visible = false
[node name="ground2" type="Sprite" parent="ParallaxBackground2/ParallaxLayer"]
modulate = Color( 0.878431, 0.286275, 0.643137, 1 )
......@@ -75,6 +42,7 @@ scale = Vector2( 0.8, 1 )
transform = Transform2D( 0.8, 0, 0, 1, 0, 0 )
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
visible = false
[node name="ground3" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
modulate = Color( 0.760784, 0.0980392, 0.494118, 1 )
......@@ -92,24 +60,11 @@ z_index = 1
position = Vector2( 533.5, 1607.5 )
texture = ExtResource( 7 )
[node name="ParallaxForeground" type="ParallaxBackground" parent="."]
layer = 10
[node name="GroundSpawner" type="Node2D" parent="."]
z_index = 100
script = ExtResource( 8 )
sprite_scene = ExtResource( 9 )
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxForeground"]
motion_scale = Vector2( 1.2, 1 )
[node name="Particles2D" type="Particles2D" parent="ParallaxForeground/ParallaxLayer"]
position = Vector2( 510, 1658.89 )
amount = 20
lifetime = 3.0
preprocess = 2.0
process_material = SubResource( 5 )
texture = ExtResource( 8 )
[node name="ground" type="Sprite" parent="ParallaxForeground/ParallaxLayer"]
modulate = Color( 0.403922, 0.2, 0.72549, 1 )
position = Vector2( 530, 1880 )
scale = Vector2( 1.19444, 1.19444 )
texture = ExtResource( 4 )
region_rect = Rect2( 0, 0, 1080, 400 )
[node name="SpawnPosition" type="Position2D" parent="GroundSpawner"]
position = Vector2( -100, 1920 )
extends Node2D
"""
"""
export var sprite_scene : PackedScene
var count_to_fill_screen : int
var camera : Camera2D
func setup(camera_node : Camera2D):
camera = camera_node
func _ready() -> void:
var sprite : Sprite = sprite_scene.instance()
count_to_fill_screen = ceil(ProjectSettings.get('display/window/size/width') / sprite.texture.get_width())
for i in range(count_to_fill_screen):
var new_sprite = sprite_scene.instance()
new_sprite.position.x = position.x + i * sprite.texture.get_width()
[gd_scene load_steps=8 format=2]
[ext_resource path="res://assets/ground.png" type="Texture" id=1]
[ext_resource path="res://assets/particle_hairy.png" type="Texture" id=2]
[sub_resource type="Gradient" id=1]
offsets = PoolRealArray( 0, 0.2, 0.834146, 1 )
colors = PoolColorArray( 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 )
[sub_resource type="GradientTexture" id=2]
gradient = SubResource( 1 )
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0.00428528, 0.0173051 ), 0.0, 1.40242, 0, 0, Vector2( 0.292929, 0.747705 ), 0.956195, 0.956195, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=4]
curve = SubResource( 3 )
[sub_resource type="ParticlesMaterial" id=5]
emission_shape = 2
emission_box_extents = Vector3( 640, 20, 1 )
flag_disable_z = true
spread = 24.68
flatness = 0.32
gravity = Vector3( 0, 40, 0 )
initial_velocity = 57.47
initial_velocity_random = 0.4
angular_velocity = 20.0
angular_velocity_random = 1.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
damping = 25.29
angle = 15.0
angle_random = 1.0
scale = 0.7
scale_random = 0.54
scale_curve = SubResource( 4 )
color_ramp = SubResource( 2 )
hue_variation_random = 1.0
[node name="Ground" type="Sprite"]
modulate = Color( 0.356863, 0.133333, 0.65098, 1 )
texture = ExtResource( 1 )
offset = Vector2( 540, -120.697 )
region_rect = Rect2( 0, 0, 1080, 400 )
[node name="PurpleMiasma" type="Particles2D" parent="."]
position = Vector2( 510, -310.41 )
amount = 20
lifetime = 3.0
preprocess = 2.0
visibility_rect = Rect2( -640, -100.058, 1280, 200 )
process_material = SubResource( 5 )
texture = ExtResource( 2 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
modulate = Color( 0.647059, 0.0117647, 0.0117647, 1 )
position = Vector2( 1090, -260 )
z_index = 100
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="queue_free"]
tool
extends Node2D
"""
Repeats a sprite hozitontally infinitely by spawning enough sprites to always
fill the view
"""
onready var spawn_position : Position2D = get_node("SpawnPosition")
export var sprite_scene : PackedScene
var WINDOW_WIDTH : int = ProjectSettings.get('display/window/size/width')
func _ready():
if Engine.editor_hint:
if not sprite_scene:
return
add_child(sprite_scene.instance())
else:
var sprite : Sprite = sprite_scene.instance()
var amount_to_fill_screen = ceil(WINDOW_WIDTH / sprite.texture.get_width())
for i in range(amount_to_fill_screen + 2):
spawn_sprite()
func spawn_sprite():
"""Offsets the spawner node and spawns a new sprite"""
var sprite : Sprite = sprite_scene.instance()
sprite.connect("tree_exited", self, "spawn_sprite")
sprite.position = spawn_position.position
call_deferred("add_child", sprite)
spawn_position.position.x += sprite.texture.get_width()
[gd_scene load_steps=2 format=2]
[ext_resource path="res://SpriteSpawner/SpriteSpawner.gd" type="Script" id=1]
[node name="SpriteSpawner" type="Node2D"]
script = ExtResource( 1 )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment