[java] Wrap objects around the screen

Started by
9 comments, last by Halsafar 18 years, 6 months ago
(Edit: Not sure if this belongs in Game Programming of Java Development. Since I'm using Java2D today I figure this is a good place.) Before I start trying to come up with some complex method to do so. I am curious if there is a way to perfectly wrap an object in java2d around the screen. Okay thats not very clear... Now I can have the object wrap fine by checking its pos against the screen edges. But what about this scenerio: - the object is half crossing the screen edge - half should be showing on one side and the other half should be showing on the other. Is there any easy way to do this? (NOTE: The object is built from lines, not an image. As with an object it would be very easy to split the rect up. A line object is not so forgiving.)
Advertisement
not too sure about what you mean... but what about drawing the lines to an image and then split the result image as needed?
This probably isn't the best option but you could draw two of your Objects, one on the opposite side of the screen with the required amount of offset to put it partially outside of the drawing area. Of course you will need to determine how much to put it outside of your viewing area which is still probably easy to determine. Of course, depending on how you set up your renderring loop, this may put two of the same elements in the entity cache for renderring, but then again if the entity has the responsibility of renderring itself then it probably is not a big deal.

This would be a pretty simple tranlation you could do to the Object Coordinate Space, and then translate it back once it is drawn on the otherside. If the Object enters a corner area and has to be drawn once for the x and then again for the y wrapping the translation is best.

L-

PS. If you mean easy as in already in the API, I don't think so, unless you want to create a clipping area and a transform to handle the same task as the one I outlined above?

[Edited by - Lucidquiet on October 9, 2005 3:02:05 PM]
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Yah Lucid I think your idea is about the only way I could achieve this...

A circular world on a flat screen :)


I was hoping maybe there was some sorta mirror API or maye some clipping functions to reflect the left out portion.

Heh do u think the Asteroids game would be any less fun if your whole ship had to be off the screen to wrap to the other side...
Yeah I think Asteroids would be a little less fun if you got that jumping sort of thing going on, where one moment its on one side of the screen and then suddenly on the other side.

Besides I'm guessing you want to do the same thing for the Asteroids and that would be really annoying to watch Asteroids jump across the screen. Cause my geuss is you would draw it on the one side until the 'center' of the thing moves beyond the border and then wrap the coordinates which would make the whole asteroid appear on the other side of the flat map.

L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Yah pretty much. What I'm doing now is just testing all 3 points on the Asteroid ship against the edges. If all three points are across then I wrap it to the other side... So there is a slight moment where ur ship is fully off the screen -- altho it is nearly impossible to remain off the screen unless u can come to a stop with like 0.00001 space between the last point and the edge.


I think I am going to see if rendering to an image is possible then render then images to the screen... That way I can render it twice and simply split up the RECT based on how far the ship is crossed the border.
In that case why not just do all images?

L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
Because I wish to simplify the collision detection with line to line or point to line rather than determine the info from an image.

I am having no luck finding Java2D Render to image info.
If you didnt know already (dont know if it is the best solution for your problem or not), the Graphics2D object has overloaded versions of drawImage() that lets you easily draw partial images, even distorting them, mirroring them, splitting them, etc. So your initial problem of drawing a partial object on one side of the screen, and another portion of it on the other side of the screen can easily be solved using that method.

Edit:

Sorry, I just saw this line:
Quote:
(NOTE: The object is built from lines, not an image. As with an object it would be very easy to split the rect up. A line object is not so forgiving.)
Development blog, The Omega Sector -- http://www.omegasector.org
you could use Graphics2D.translate(int,int), and that way you'll just call the draw method twice, with the translation between them...
have you thought about the colissions? if the object is at two parts of the screen you have to check colission for each part...

This topic is closed to new replies.

Advertisement