Commit 286ee78a authored by Nathan Lovato's avatar Nathan Lovato
Browse files

Add fence sprite, make infinite repeat work with scaled sprites

parent b0377f52
Pipeline #5059 passed with stage
in 44 seconds
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://assets/bg.png" type="Texture" id=2]
[ext_resource path="res://ScoreLabel/ScoreLabel.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/ground.png" type="Texture" id=4]
[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://SpriteSpawner/SpriteSpawner.gd" type="Script" id=7]
[ext_resource path="res://SpriteSpawner/Fence.tscn" type="PackedScene" id=8]
[ext_resource path="res://SpriteSpawner/SpriteSpawner.gd" type="Script" id=5]
[ext_resource path="res://SpriteSpawner/GroundPink.tscn" type="PackedScene" id=6]
[ext_resource path="res://PillarSpawner/PillarSpawner.tscn" type="PackedScene" id=7]
[ext_resource path="res://Gnu/Gnu.tscn" type="PackedScene" id=8]
[ext_resource path="res://SpriteSpawner/GroundSprite.tscn" type="PackedScene" id=9]
[ext_resource path="res://SpriteSpawner/Fence.tscn" type="PackedScene" id=10]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
[node name="BackgroundLayer" type="CanvasLayer" parent="."]
editor/display_folded = true
layer = -10
[node name="Sky" type="Sprite" parent="BackgroundLayer"]
......@@ -29,47 +29,55 @@ scale = Vector2( 0.66, 1 )
transform = Transform2D( 0.66, 0, 0, 1, 0, 0 )
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground2"]
visible = false
motion_scale = Vector2( 0.8, 1 )
[node name="ground2" type="Sprite" parent="ParallaxBackground2/ParallaxLayer"]
modulate = Color( 0.878431, 0.286275, 0.643137, 1 )
position = Vector2( 425, 1517.41 )
position = Vector2( 424.242, 1520 )
scale = Vector2( 0.787037, 0.787037 )
texture = ExtResource( 4 )
region_rect = Rect2( 758, 159, 311, 122 )
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
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 )
position = Vector2( 540, 1640 )
texture = ExtResource( 4 )
[node name="GroundSpawnerPink" type="Node2D" parent="ParallaxBackground/ParallaxLayer"]
position = Vector2( -180, 1640 )
z_index = 100
script = ExtResource( 5 )
sprite_scene = ExtResource( 6 )
[node name="SpawnPosition" type="Position2D" parent="ParallaxBackground/ParallaxLayer/GroundSpawnerPink"]
[node name="PillarSpawner" parent="." instance=ExtResource( 5 )]
[node name="PillarSpawner" parent="." instance=ExtResource( 7 )]
position = Vector2( 0, 950 )
[node name="Gnu" parent="." instance=ExtResource( 6 )]
[node name="Gnu" parent="." instance=ExtResource( 8 )]
position = Vector2( 190, 960 )
z_index = 1
[node name="Area2D" type="Area2D" parent="."]
position = Vector2( 0, 1930 )
[node name="FenceSpawner" type="Node2D" parent="."]
position = Vector2( -180, 1640 )
z_index = 100
script = ExtResource( 7 )
sprite_scene = ExtResource( 8 )
[node name="SpawnPosition" type="Position2D" parent="FenceSpawner"]
[node name="GroundSpawner" type="Node2D" parent="."]
position = Vector2( -180, 1940 )
position = Vector2( -180, 1930 )
z_index = 100
script = ExtResource( 7 )
script = ExtResource( 5 )
sprite_scene = ExtResource( 9 )
[node name="SpawnPosition" type="Position2D" parent="GroundSpawner"]
[node name="FenceSpawner" type="Node2D" parent="."]
editor/display_folded = true
position = Vector2( -180, 1700 )
z_index = 100
script = ExtResource( 5 )
sprite_scene = ExtResource( 10 )
[node name="SpawnPosition" type="Position2D" parent="FenceSpawner"]
......@@ -3,21 +3,21 @@
[ext_resource path="res://assets/fence.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 540, 20 )
extents = Vector2( 260, 20 )
[node name="Fence" type="Sprite"]
texture = ExtResource( 1 )
offset = Vector2( 533.5, -60 )
offset = Vector2( 271, -60 )
[node name="VisibilityEnabler2D" type="VisibilityNotifier2D" parent="."]
position = Vector2( 1080, 0 )
position = Vector2( 530, 0 )
[node name="Area2D" type="StaticBody2D" parent="."]
collision_layer = 2
collision_mask = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 540, -110 )
position = Vector2( 260, -110 )
shape = SubResource( 1 )
[connection signal="screen_exited" from="VisibilityEnabler2D" to="." method="queue_free"]
......@@ -9,7 +9,8 @@ onready var spawn_position : Position2D = get_node("SpawnPosition")
export var sprite_scene : PackedScene
var WINDOW_WIDTH : int = ProjectSettings.get('display/window/size/width')
var WINDOW_WIDTH : float = ProjectSettings.get('display/window/size/width')
var sprite_width := 0.0
func _ready() -> void:
......@@ -18,7 +19,8 @@ func _ready() -> void:
spawn_position.add_child(sprite_scene.instance())
else:
var sprite : Sprite = sprite_scene.instance()
var amount_to_fill_screen = ceil(WINDOW_WIDTH / sprite.texture.get_width())
sprite_width = sprite.texture.get_width() * sprite.scale.x
var amount_to_fill_screen = ceil(WINDOW_WIDTH / sprite_width)
for i in range(amount_to_fill_screen + 2):
spawn_sprite()
......@@ -28,5 +30,5 @@ func spawn_sprite() -> void:
var sprite : Sprite = sprite_scene.instance()
sprite.connect("tree_exited", self, "spawn_sprite")
sprite.position = spawn_position.position
add_child(sprite)
spawn_position.position.x += sprite.texture.get_width()
call_deferred("add_child", sprite) # to avoid error on reload
spawn_position.position.x += sprite_width
game/assets/fence.png

91.9 KB | W: | H:

game/assets/fence.png

55 KB | W: | H:

game/assets/fence.png
game/assets/fence.png
game/assets/fence.png
game/assets/fence.png
  • 2-up
  • Swipe
  • Onion skin
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