Skip to content

Instantly share code, notes, and snippets.

@Kaifungamedev
Created May 10, 2023 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kaifungamedev/ca2ffa46c6c08ddd74514b310f8d4f3c to your computer and use it in GitHub Desktop.
Save Kaifungamedev/ca2ffa46c6c08ddd74514b310f8d4f3c to your computer and use it in GitHub Desktop.
extends Node2D
var off_screen
var resetpos
var speed = -100
# Called when the node enters the scene tree for the first time.
func _ready():
off_screen = $BackgroundEmpty.position.x * -1
resetpos = $BackgroundEmpty2.position.x
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
$BackgroundEmpty.position.x += speed * delta
$BackgroundEmpty2.position.x += speed * delta
if $BackgroundEmpty.position.x <= off_screen:
$BackgroundEmpty.position.x = resetpos
if $BackgroundEmpty2.position.x <= off_screen:
$BackgroundEmpty2.position.x = resetpos
[gd_scene load_steps=3 format=3 uid="uid://b44uioaarp3k1"]
[ext_resource type="Script" path="res://looping_background.gd" id="1_mf8hi"]
[ext_resource type="Texture2D" uid="uid://8rb07mkgsb4e" path="res://backgroundEmpty.png" id="2_bh0k8"]
[node name="looping_background" type="Node2D"]
script = ExtResource("1_mf8hi")
[node name="BackgroundEmpty" type="Sprite2D" parent="."]
position = Vector2(576, 324)
scale = Vector2(1.125, 0.632813)
texture = ExtResource("2_bh0k8")
[node name="BackgroundEmpty2" type="Sprite2D" parent="."]
position = Vector2(1728, 324)
scale = Vector2(1.125, 0.632813)
texture = ExtResource("2_bh0k8")
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="scrolling background"
run/main_scene="res://looping_background.tscn"
config/features=PackedStringArray("4.0", "GL Compatibility")
config/icon="res://icon.svg"
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
@Kaifungamedev
Copy link
Author

backgroundEmpty

@Kaifungamedev
Copy link
Author

save.webm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment