Wrap images around game window

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Wrap images around game window

Post 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!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Wrap images around game window

Post by Jasoco »

You'll have to draw the image twice. Once at each edge.
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: Wrap images around game window

Post 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!
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: Wrap images around game window

Post 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!
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: Wrap images around game window

Post by MasterLee »

Crossing the borders would need to draw the sprite four times
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Wrap images around game window

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: Wrap images around game window

Post by MasterLee »

I mean crossing the borders, not the border. But i had to state it clearer crossing both borders.
Lucyy
Citizen
Posts: 51
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Re: Wrap images around game window

Post 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
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Wrap images around game window

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Lucyy
Citizen
Posts: 51
Joined: Thu Oct 15, 2015 6:57 am
Contact:

Re: Wrap images around game window

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Bobble68 and 47 guests