#### Archived

This topic is now archived and is closed to further replies.

# Making my world wrap

This topic is 6042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m writing a 2D side scroller, and its got stars and evil bugs flying around in the world. When the spaceship flies to an edge f the world, I want it to seamlessly wrap around. I''ve looked at TotWGPG''s Outpost code, and I see how the stars work for wrap-around, but the stuff like asteroids and junk don''t wrap. It doesn''t look too seamless. How do I do I make it wrap seamlessly?

##### Share on other sites
How are you displaying these images?

##### Share on other sites
Try using modulo in the point placing code...

For instance:

x = 640
y = 0

putPixel( x, y )

would place the pixel outside the screen @ 640x480 res...
but:

putPixel( x%XRES, y%YRES )

would place the pixel @ (640%640 = 0, 0%480 = 0)...
but:

x = -1
y = 0

putPixel( x%XRES, y%YRES )

would place @ ( -1, 0 )
so:

putPixel( (x+XRES)%XRES, (y+YRES)%YRES )

would make:

( (-1 + 640)%640 = 639%640 = 639, 0 )

So:

putPixel( (x+XRES)%XRES, (y+YRES)%YRES )

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631737
• Total Posts
3001944
×