0 votes

How do i make a One Screen game with a moving Object (Sprite for example) that when it goes Offscreen it come back from the opposite side from the screen

please help im big noob :/ with Script if possible

in Engine by (133 points)

1 Answer

+1 vote
Best answer

Minimally, a screen-wrap really only amounts to something like:

position.x = wrapf(position.x, screen_min_x, screen_max_x)
position.y = wrapf(position.y, screen_min_y, screen_max_y)

That wrapf() function takes a specified value (the first argument) and forces it to land within the specified min and max values (the second 2 arguments).

If the specified value is less than the minimum value, the function returns the maximum value. If the specified value is greater than the maximum value, the function returns the minimum value. That's how the "wrap" works.

So, if you set those screen_min_* and screen_max_* values correctly for your game bounds, something like the above should work.

by (10,914 points)
selected by
Is this wrapf function built into Godot
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.