🔒 Locked
[java] Wrap objects around the screen
Advertisement
Original Post
(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.)
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]
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]
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...
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-
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-
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.
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-
L-
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:
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.)
Well I did some research.
I went and played many Asteroid Clones from all sorts of languages. Including the one I made in C++ where I didn't account for this at all.
It seems none of them account for this... There is always a time where you ship "could" remain just off the screen with only a fraction of the line still remaining on the screen that you cannot see it but the ship won't wrap...
To many flaws in the game design comes up trying to account for this and seeing that other don't I don't think I'm goona bother for such a simple game as this.
Out all the games of Asteroids I played I never found the original... I assume I could find an Atari emulator and play it for a day...
I went and played many Asteroid Clones from all sorts of languages. Including the one I made in C++ where I didn't account for this at all.
It seems none of them account for this... There is always a time where you ship "could" remain just off the screen with only a fraction of the line still remaining on the screen that you cannot see it but the ship won't wrap...
To many flaws in the game design comes up trying to account for this and seeing that other don't I don't think I'm goona bother for such a simple game as this.
Out all the games of Asteroids I played I never found the original... I assume I could find an Atari emulator and play it for a day...
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement