Wraping physics objects around the edge of the screen

Does a simple way exist to make it so when a physics objects leaves the edge of a screen it would appear on the other side of the screen?

the only way i can think of doing it is to make another physics object which would mimic the movements of the objects on screen but offset it by the room width or height.
 

YoSniper

Member
The simple interaction code would be something like:
Code:
if x < 0 {
    x += room_width;
} else if x >= room_width {
    x -= room_width;
}
This alone would create a choppy sort of wrapping transition, but it would work. If you want it to look like a smoother wrap around, like the object is entering into frame while it's also exiting frame, you would want to do something like this in the Draw Event:
Code:
var xx;
for(xx = -room_width; xx < 2 * room_width; xx += room_width) {
    draw_sprite(sprite_index, image_index, x + xx, y);
}
 
@YoSniper

box2d physics are also added into the mix so its a bit hard

i could just create another physicvs object and have it match its movements based on the phy_speed_x and y, and that might work, but i would be dramatically increasing the amount of physics objects colliding with one another if i did.

thank you.
 
Top