Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ISVios |
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
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