0 votes

Hi, I'm new to godot engine and was trying to make a flappy bird clone for learning.
I plan to instantiate the background sprite from right going to left such that the speed at which sprite moves and the interval between instancing its copies make the background seem infinite. As of collecting the out of view sprites i came across scripting docs and found

func _on_Visibility_screen_exited():



tried to test it but it didn't work, (the node tab for sprite only shows Visibility_Changed() function only)

so my queries are:
1. how to instantiate sprite backgrounds?
2. how to manage their interval of instantiating such that they seem continous. (I've kept the sprite speed to 1)?
3. how do i code the sprite's script such that it deletes itself when exiting the view?

I'm using Godot v3, the root node is a sprite and scene contains no other node.
so far i've only manged to make the sprite move by the code:

extends Sprite

var vel = Vector2(1, 0)

func _ready():

func _process(delta):
    set_position(get_position() + vel)
in Engine by (14 points)

1 Answer

0 votes
exends Node2D

func _ready():
    # creating 2 new sprites via script
    for i in range(2):
        var sprite = Sprite.new()
        sprite.name = "Sprite" + str(i)

func _process(delta):
    # move both sprites and reset their positions if they go off the
    # assuming portrait mode at 1080 x 1920 and scrolling to the left
    for c in get_children():
        c.translate(Vector2(-360, 0) * delta) # moving 1/3 of the
            screen width per sec
        if c.position.x < -1080:
            c.position.x = 1080

Deleting them with queue_free at the end of their movement is unnecessary, since you can just string them together.

by (840 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.