Object goes Offscreen come from Opposite side

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

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 :confused: with Script if possible

:bust_in_silhouette: Reply From: jgodfrey

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.