Implement sprite appearing on other side of screen when left it

Hi,

I want to implement functionality that will allow objects with sprites to travel through screen’s border and appear on other side.
Of course I can do coordinate check and if position point lefts visible part of screen it changes it to related from other side.
But problem is that object is NOT a point, it has a sprite, and I want that if any part of sprite lefts visible part of screen that part appears on other side.
One approach that goes to my mind is to create a second object, but it will make game architecture wierd…
Do anyone have an ideas how to implement it.
Picture will show what I mean.

Hey @Headmower

You don’t actually need to create a second object, you would just need to draw a second sprite at the right position as well as the rectangle for the collision detection.

If you want to try out a more advanced technique then feel free to check out this gist:

It wraps Texture2Ds around the screen by using a set of RenderTarget2Ds.

1 Like

Thank you, sqrMin1!
I just implemented it as (in some conditions) that object is drawing it’s duplicate texture on other calculated point.
May be I will try approach that you linked from github.

1 Like