@tool
class_name FakeParallax
extends Node2D

@export  var rate = 0.0
@onready var base_position = get_position()
@onready var camera = get_tree().get_root().find_child("Camera", true, false)
var notifier: VisibleOnScreenNotifier2D = VisibleOnScreenNotifier2D.new()

func _ready():
    if camera and !Engine.is_editor_hint():
        notifier.set_rect(Rect2(Vector2(-1920.0, -1080.0), Vector2(3840.0, 2160.0)))
        add_child(notifier)
        camera.connect("camera_moved", _update)
        _update(true)

func _update(force: bool = false):
    if force or notifier.is_on_screen():
        if camera:
            var delta = camera.get_screen_center_position() - base_position 
            set_position(base_position + delta * rate)
