This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello.
The other day I decided to make a small screensaver but ran into a problem.
I can’t find a solution to how to implement an artificial “endless room” where elements (like Sprite) would partially display outside the screen and would be displayed on the other side.

Sorry for my English. It isn't my native language.

With regards, Vios

in Engine by (14 points)

The best way would be through a shader, but I don't know how to implement it, but if it doesn't bother you that the sprite disappears completely, the wrapf function is ideal:

float wrapf(value: float, min: float, max: float)
Wraps float value between min and max.
Usable for creating loop-alike behavior or infinite surfaces.

extends Node2D
onready var sprite= $Sprite;
onready var screen= get_viewport_rect();
var time= 0.0

func _process(delta):
    time += 5 * delta
    sprite.position.x= wrapf(sprite.position.x + 8, -50, screen.size.x)
    sprite.position.y= wrapf(sprite.position.y + sin(time) * 20, -50, screen.size.y)

1 Answer

0 votes

When a sprite enters a screen border, you could duplicate that sprite on the opposite border and have it move together with the other one. When either of the two completely leaves a border, destroy the one that's outside the screen.

by (190 points)

Thanks for answer.
But if I have many elements more than 1000 ? Of course, not all elements will run off the screen at the same time.I need save clone one if element move to corner.

Thanks, again. I go try.

With regards, Vios.

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 Frequently asked questions and 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 [email protected] with your username.