Infinity "room".

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ISVios

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

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)

estebanmolca | 2019-12-17 09:31

:bust_in_silhouette: Reply From: null_digital

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.

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.

ISVios | 2019-12-16 14:07