Wrapping sprites around screen edges
by Philip Mansfield · in Torque Game Builder · 08/28/2006 (10:34 am) · 8 replies
Back in the depths of time, there was a WRAP option for the world limt. It was taken out as it caused some confusion (and possibly wasn't working correctly?). But it would be really nice if it could be fixed up and reimplemented.
What would be super nice is if images are partially wrapped as well. So as a plane flies out the right hand side, it's nose starts to appear on the left.
I could do the 'wrap warp' and just make a plane disappear from the right hand side and reappear on the left hand side, but that looks quite rubbish, and if the player is near two screen edges, the plane coule warp about all over the place.
Hmm, I wonder if I can make the image a tile, and the player actually controls the tile layer...
Edit - Oops, meant to put this in the Suggestions forum.
What would be super nice is if images are partially wrapped as well. So as a plane flies out the right hand side, it's nose starts to appear on the left.
I could do the 'wrap warp' and just make a plane disappear from the right hand side and reappear on the left hand side, but that looks quite rubbish, and if the player is near two screen edges, the plane coule warp about all over the place.
Hmm, I wonder if I can make the image a tile, and the player actually controls the tile layer...
Edit - Oops, meant to put this in the Suggestions forum.
#2
I'm going to give it a shot tonight.
08/28/2006 (11:36 am)
It's funny you mentioned that, because I started thinking something similar just after I posted :)I'm going to give it a shot tonight.
#3
09/12/2006 (1:04 pm)
I lifted the script from the Asteroids tutorial, but it just warps it around to the other side, it doesn't show half/half. Though I'm curious why you'd want it split like that?
#4
09/12/2006 (1:37 pm)
I dunno, I think it'd be easier for less experienced gamers to see the plane stradling the screen edges. However I've gone for the warp effect now and will combine it with a brief protective shield to give the player the second or so they might need to relocate their plane.
#5
09/12/2006 (4:53 pm)
^Actually, that's inspired me a little bit. I've noticed some people get thrown off by the edge-wrap as well. I might have to fiddle with some sort of pop-in/pop-out effect. :)
#6
Not too hard to handle... Just add a field to the sprite that keeps track of the duplicate sprite (and do the same for the duplicate -- link it to the original), and when a sprite gets "killed", check for a duplicate, and if so, kill it too.
09/13/2006 (1:41 pm)
One thing you must be careful about if you create a duplicate sprite coming out the left as the one on the right is disappearing, is collisions. Let's say the plane on the right gets hit with a bullet as it's going away, but this is *after* a duplicate was created on the left. The duplicate on the left must blow up also. Same for a bullet hitting the one on the left.Not too hard to handle... Just add a field to the sprite that keeps track of the duplicate sprite (and do the same for the duplicate -- link it to the original), and when a sprite gets "killed", check for a duplicate, and if so, kill it too.
#7
I have been playing with "wrapping" a plane and the solution that seems to be working for me is, I set the world limits to be the camera view + sprite size. This causes the plane to just disappear off of one edge then I can simply move the position of the plane to the opposite side world limit + .5 * sprite size. It seems to flow fairly smoothly and I find that most players find it acceptable. It can cause a little disorientation as you can get in a situation where the plane is almost completely off the screen and if the velocity is moving from an x to y axis in the moment the plane gets lost to the player off the edge of the screen . I have created acceleration/deceleration effects on the plane to give it some realism and it also helps with the wrapping because you can't stop the sprite instantly. You could also play with trimming the world limits so the plane doesn't quite disappear of of one edge before it is moved to the other side. As long as the object is in motion this would still give the player that spherical world sensation.
09/15/2006 (6:02 am)
Thinking about wrap and how you could implement this. If you want to handle very specific cases you could probably get away with cloning the sprite and as Vern said checking collisions on both. But when you start really getting into having duplicate images and trying to keep them synced, you have to ensure that all parameters of the duplicate are matching the original. Say I had a bouncing/spinning ball that I wanted to wrap. I would not only have to sync collisions, but velocities, rotation, gravitational effects, etc. This could grow very complex very quickly. I have been playing with "wrapping" a plane and the solution that seems to be working for me is, I set the world limits to be the camera view + sprite size. This causes the plane to just disappear off of one edge then I can simply move the position of the plane to the opposite side world limit + .5 * sprite size. It seems to flow fairly smoothly and I find that most players find it acceptable. It can cause a little disorientation as you can get in a situation where the plane is almost completely off the screen and if the velocity is moving from an x to y axis in the moment the plane gets lost to the player off the edge of the screen . I have created acceleration/deceleration effects on the plane to give it some realism and it also helps with the wrapping because you can't stop the sprite instantly. You could also play with trimming the world limits so the plane doesn't quite disappear of of one edge before it is moved to the other side. As long as the object is in motion this would still give the player that spherical world sensation.
//This assumes a sprite size of 16x16 we could change it to get the size of the calling object
//Worldlimit is set to camera size + objectsize * 2
function playerShip::onWorldLimit(%this, %mode, %limit)
{
switch$ (%limit)
{
case "left":
%this.setPositionX(%this.getWorldLimitmaxX() - 8);
case "right":
%this.setPositionX(%this.getWorldLimitminX() + 8);
case "top":
%this.setPositionY(%this.getWorldLimitmaxY() - 8);
case "bottom":
%this.setPositionY(%this.getWorldLimitminY() + 8);
}
}
#8
I haven't spent a lot of time tweaking the wrapping yet as I've had other bits of code to get going instead. I hope to go over all that kind of stuff this weekend, and if I come up with any interesting I'll be sure to post it here.
09/15/2006 (6:09 am)
That's kind of how I'm doing it. Another problem that I've also noticed is that my plane is constantly moving forward, and the player just changes the rotation angle. If the player performs a loop near the screen edge, there seems to some 'jiggling' going on as the player is warped from one side to the other and then back again as the rotation changes.I haven't spent a lot of time tweaking the wrapping yet as I've had other bits of code to get going instead. I hope to go over all that kind of stuff this weekend, and if I come up with any interesting I'll be sure to post it here.
Torque Owner Apurva Amin