- Home /
How do I render 2D Sprites partially (side to side teleport)
I'm new to Unity as well as game engines and am still learning how to deal with cameras, rendering and the like.
My first project is an attempt to execute a lot of basic mechanical tropes in 2D platformers. I am using Unity in it's 2D layout with 2D assets.
Currently, I'm trying to have the edges of the screen be connected, meaning if you jump off the right side of the screen, you will show up on the left side and vice-verse.
This is very easy to do in the basic position (transform) sense, but I'm unsure how to approach actual rendering.
I'd like to have the sprite show up partially at each side of the screen if she is currently in between. I want to have 0 space between the left and right side of the screen. When you walk off the right side, the sprite starts appearing on the left side of the screen immediately.
Code samples are highly appreciated!
Thank you.
The only way I can thing to do this in Unity Free is a bit of slight of hand with an extra copy of the object...might get tricky if you want the extra copy to be impacted by things like collisions.
That was the way I thought to do it, but I was wondering if there's a better option. Doesn't seem to be without pro. =\
Answer by legion_44 · Jan 13, 2014 at 08:35 PM
If you use pro version. You could do this using RenderTexture.
http://docs.unity3d.com/Documentation/ScriptReference/RenderTexture.html
If you have pro version comment and I will write something like tutorial how to do this.
Hope that helps you somehow,
Paul
As I mentioned I'm new to Unity and currently a student so I don't have pro and don't intend to get it any time soon.
Any other options you see possible except for creating a copy?
Edit: I have a friend with Unity Pro and I'd love to at least test it out there. Could you elaborate a little bit about the Render Texture solution?
Any example code will be highly appreciated!
Answer by KOKOStern · Jan 15, 2014 at 08:21 PM
I ended up creating a clone on the opposing side of the screen and then teleporting to it and destroying it when my original gets completely out of the screen.
The clone is an imperfect one, which means it's a different prefab. The only difference is in the "side to side teleport" script. The original can create clones once he reaches the proper point, and if he goes beyond the screen, he teleport to the location of the clone, and destroys it. The clone can not create other clones himself, but does destroy himself if he ever goes off screen (which means the original decided not to go all the way out of the screen).
This explanation is kind of hard to follow. I made a video that shows it in action if that helps. (The video does not contain code).
Answer by jason_barnes · Apr 02, 2014 at 07:17 PM
This might be helpful even though the solution is more of a hack.
Your answer
Follow this Question
Related Questions
Sprite leaves a tail behind it in PlayMode 0 Answers
Portal between scenes? 3 Answers
"Warping/Teleporting Out" Objects in space 2 Answers
making a non walk through portal 2 Answers
URP 2D renderer not working 1 Answer