Add scrolling background to game
This commit is contained in:
parent
a7612be80a
commit
518b672fc7
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://d2had6j0ul7hn"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://d2had6j0ul7hn"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://b5plspvrerf8c" path="res://assets/background/rocks_2.png" id="1_kihwf"]
|
||||
[ext_resource type="Script" path="res://game/game.gd" id="1_mh8bq"]
|
||||
[ext_resource type="PackedScene" uid="uid://dnu582ov5o310" path="res://plane/plane.tscn" id="2_xl0om"]
|
||||
[ext_resource type="PackedScene" uid="uid://tlvvmodg5soo" path="res://scrolling_background/scrolling_background.tscn" id="3_h3bfe"]
|
||||
[ext_resource type="PackedScene" uid="uid://bed61tdnf2vq7" path="res://pipes/pipes.tscn" id="3_njdgd"]
|
||||
[ext_resource type="PackedScene" uid="uid://bjx4v08mh6uhy" path="res://game_over/game_over.tscn" id="5_pro41"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpkbp3vf7sy4b" path="res://hud/hud.tscn" id="6_8typh"]
|
||||
|
@ -16,7 +17,10 @@ size = Vector2(499, 20)
|
|||
script = ExtResource("1_mh8bq")
|
||||
pipes_scene = ExtResource("3_njdgd")
|
||||
|
||||
[node name="ScrollingBackground" parent="." instance=ExtResource("3_h3bfe")]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(249, 367)
|
||||
texture = ExtResource("1_kihwf")
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
extends ParallaxBackground
|
||||
|
||||
const SPEED: float = 120.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
GameManager.on_game_over.connect(on_game_over)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
scroll_offset.x += SPEED * delta * -1
|
||||
|
||||
|
||||
func on_game_over() -> void:
|
||||
set_process(false)
|
|
@ -0,0 +1,26 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://tlvvmodg5soo"]
|
||||
|
||||
[ext_resource type="Script" path="res://scrolling_background/scrolling_background.gd" id="1_2tit7"]
|
||||
[ext_resource type="PackedScene" uid="uid://lyxdlorebi57" path="res://scrolling_background/scrolling_layer.tscn" id="2_xr7tv"]
|
||||
[ext_resource type="Texture2D" uid="uid://catcpw8b2gbou" path="res://assets/background/sky.png" id="3_s8hsv"]
|
||||
[ext_resource type="Texture2D" uid="uid://beyem76sprrai" path="res://assets/background/clouds_2.png" id="4_ebcr1"]
|
||||
[ext_resource type="Texture2D" uid="uid://clhm76pnyn0ja" path="res://assets/background/rocks_1.png" id="5_cgbuy"]
|
||||
[ext_resource type="Texture2D" uid="uid://b5plspvrerf8c" path="res://assets/background/rocks_2.png" id="6_4ivtk"]
|
||||
|
||||
[node name="ScrollingBackground" type="ParallaxBackground"]
|
||||
script = ExtResource("1_2tit7")
|
||||
|
||||
[node name="ScrollingLayer" parent="." instance=ExtResource("2_xr7tv")]
|
||||
texture = ExtResource("3_s8hsv")
|
||||
|
||||
[node name="ScrollingLayer2" parent="." instance=ExtResource("2_xr7tv")]
|
||||
texture = ExtResource("4_ebcr1")
|
||||
scroll_scale = 0.2
|
||||
|
||||
[node name="ScrollingLayer3" parent="." instance=ExtResource("2_xr7tv")]
|
||||
texture = ExtResource("5_cgbuy")
|
||||
scroll_scale = 0.5
|
||||
|
||||
[node name="ScrollingLayer4" parent="." instance=ExtResource("2_xr7tv")]
|
||||
texture = ExtResource("6_4ivtk")
|
||||
scroll_scale = 0.7
|
|
@ -0,0 +1,18 @@
|
|||
extends ParallaxLayer
|
||||
|
||||
@export var texture: Texture
|
||||
@export var scroll_scale: float = 0.0
|
||||
@export var texture_x: float = 1920.0
|
||||
@export var texture_y: float = 1080.0
|
||||
|
||||
@onready var sprite_2d = $Sprite2D
|
||||
|
||||
|
||||
func _ready():
|
||||
motion_scale.x = scroll_scale
|
||||
|
||||
var scale_factor = get_viewport_rect().size.y / texture_y
|
||||
sprite_2d.texture = texture
|
||||
sprite_2d.scale = Vector2(scale_factor, scale_factor)
|
||||
|
||||
motion_mirroring.x = texture_x * scale_factor
|
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://lyxdlorebi57"]
|
||||
|
||||
[ext_resource type="Script" path="res://scrolling_background/scrolling_layer.gd" id="1_palkg"]
|
||||
|
||||
[node name="ScrollingLayer" type="ParallaxLayer"]
|
||||
script = ExtResource("1_palkg")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
centered = false
|
Loading…
Reference in New Issue