Page 1 of 3

Wrap images around game window

Posted: Tue Apr 11, 2017 11:33 am
by OnACoffeeBreak
Without checking the boundaries of a window, an image/sprite will gradually disappear beyond the edge of the window as the player/enemy moves out of bounds. Is it possible to keep this behavior, but have the part of the image that is beyond the window boundary appear along the opposite boundary? In other words, an image moving to the right out of the window will gradually disappear into the right side of the window and at the same time gradually reappear on the left side.

Code: Select all

[       .o0* ]
[        .o0*]
[*        .o0]
[0*        .o]
[o0*        .]
[ .o0*       ]
I know this is possible to do with shapes drawn with Love, but I haven't been able to figure out how to do it with an image.

Thanks!

Re: Wrap images around game window

Posted: Tue Apr 11, 2017 1:10 pm
by Jasoco
You'll have to draw the image twice. Once at each edge.

Re: Wrap images around game window

Posted: Tue Apr 11, 2017 1:48 pm
by OnACoffeeBreak
Ha! Thanks! I'm grinning IRL because that is such an obvious solution. This foray into game making has so far been full of these little nuggets and little Eureka moments. It reminds me why I've gotten into programming to begin with.

Appreciate your help!

Re: Wrap images around game window

Posted: Tue Apr 11, 2017 10:29 pm
by OnACoffeeBreak
So, on the surface this seemed simple. Handling crossing of borders when the image is only crossing a single edge is easy enough, but handing crossing at corners is more involved. I'll have to think on this overnight. Thanks!

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 4:53 am
by MasterLee
Crossing the borders would need to draw the sprite four times

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 6:44 am
by zorg
MasterLee wrote: Wed Apr 12, 2017 4:53 am Crossing the borders would need to draw the sprite four times
No it wouldn't; why would it?

Also, just note how far on both axes is the image beyond the edge in one place, and just use those values subtracted from the image's dimensions in the other place.

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 10:07 am
by MasterLee
I mean crossing the borders, not the border. But i had to state it clearer crossing both borders.

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 11:33 am
by Lucyy
MasterLee wrote: Wed Apr 12, 2017 10:07 am I mean crossing the borders, not the border. But i had to state it clearer crossing both borders.
Even if you're crossing multiple borders you'd only need to draw your image twice

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 11:34 am
by zorg
MasterLee wrote: Wed Apr 12, 2017 10:07 am I mean crossing the borders, not the border. But i had to state it clearer crossing both borders.
Okay, i see what you mean, yeah, worst case, one needs 4 sprites.
Lucyy wrote: Wed Apr 12, 2017 11:33 am Even if you're crossing multiple borders you'd only need to draw your image twice
At first i thought this too, but i was wrong after i drew it in mspaint; a square (the sprite image) can occupy all 4 corners simultaneously when wrapped around one of them, so that means 4 sprites.

Re: Wrap images around game window

Posted: Wed Apr 12, 2017 11:41 am
by Lucyy
zorg wrote: Wed Apr 12, 2017 11:34 am At first i thought this too, but i was wrong after i drew it in mspaint; a square (the sprite image) can occupy all 4 corners simultaneously when wrapped around one of them, so that means 4 sprites.
Oh, I see what you mean. I guess it depends on how you wrap the image I suppose.
I assumed that the corners would wrap too, like if your image leaves the top side of the screen it's come out at the bottom and if it goes out on the left it'll appear on the right that would mean that crossing both the top and left side it would appear at the bottom right side. And that would only require you to draw 2 images.