Scroller suggestions

I want to build a scroller that allows a centered avatar to move around. Don’t need tiles, though may have a static background image. Really just need black “space” with the ability to move around a 2048*2048 area with static objects at x y locations throughout. Space station at 100,100. Black hole at by 1075 by 987, etc…

Would you guys still recommend tiles, large pic, large (dirty?) rectangle, etc. ?

Sounds like you could get away without tiles. Uses lists of objects that are in the level and make sure they are properly sorted. Paint the objects until you reach one that isn’t on the screen… since the list is sorted you know the rest aren’t on the screen either. Keep track of the first item in the list that is visible etc…

Fantastic! The sorting of lists…should this list be resorted every game loop based on your ships posistional x and y? Thus adjusting who is and is not visible and sorting visible down to non-visible?

Excluding the above, this should provide a great framerate and less of a headache when moving to network play down the road since there is not heavy background repaint.

Thought just occured…list can also be sorted by your ships scanner range to what you can detect and what you can’t, I would assume. “Beware cloaked ships!”

Mickey

Well, I don’t have much experience with tiles, but for my little window-mode space scroller, I keep a sorted ArrayList of regions that don’t contain a sprite. Since my sprites cover 80-90% of my background (which is actually generated on the fly) at any given time, this seems to work pretty well for me. Thus, as I go through and draw my list of sprites, I store a rectangle of the region between each individual sprite, sort it and then paint the background as appropriate at the end. Maybe a sort of pseudo-tile implementation? Anyway, like I said, it seems to work well for me because 1. My background is fairly simple (black with white pixels for stars) and 2. My sprites cover the majority of the background most of the time. Anyway, don’t know if any of that is useful to you, but it’s what I know. Good luck on it.

If you have relatively few sprites/objects (say 100) then you wouldn’t even need to keep them sorted. For a backround just use a ‘starfield’. You wouldn’t even have to constrain yourself to 2048x2048. Although 100,000x100,000 may seem awefully empty with only 100 objects in it …

if that scenario will work, I may not need 100k * 100k, but 10k by 10k in some sectors might provide some places for pirates, “private” trade transactions, etc to take place. Thanks.

thanks to all for all the help and suggestions!!

I have completed a little test screen, full screen, ship in center with full rotate(using AffineTransform rotate for now) and a few static objects in space. When you push the up arrow, the static objects move inthe direction opposite of the ship, thus giving the illusion of moving forward.

Works great with one big problem! When I got it working, my first thought was…wow, this is just like SubSpace(which I truly miss << correction!! I had not played in a while and was not aware it was back. I knew of Continuum but during the poor access transition, I stopped palying. i found it last night and played…wooohooo! SO I will do my space trader game instead of reinventing the wheel!) and now I am torn between my space trading game and a subspace clone!! doh!

ok, having a little translation brain freeze.

Have a 2000 by 2000 space sector(playing field).

Player will start at center of this. sectorWidth/2 sectorHeight/2

Player ship needs to be centered on glass (800 * 600 fullscreen mode)

Space Station image is at sector based 100 by 100.

When player moves, station should remain at sector coordinates 100 by 100, but move closer to me
as the screen translates…

I thought I had this working, but relized that my 100 by 100 station is actually on glass 100 by 100

any thoughts?

M

below is the code snippet that centers my ship and allows rotation and tracks the actual sector x and y properly. the drawString shows actualX and actualY at 1000,1000 and adjusts properly based on the direction the ship is going:


// adjust ships actual sector x and y  GOOD
x += Math.sin(facing) * speed;
y -= Math.cos(facing) * speed;
int actualX = Math.round(x);  // gives actual sector x
int actualY = Math.round(y);  // gives actual sector y

AffineTransform at = new AffineTransform();
at.translate(400,300);
at.rotate(facing,ship[speed].getWidth(null)>>1,ship[speed].getHeight(null)>>1);

g.setTransform(at);
g.drawImage(ship[speed], 0, 0, null);
g.drawString(" " + actualX + " : " + actualY, 0,0);

You need to think about the difference between ‘absolute coordinates’ (or ‘world coordintates’) and ‘screen coordinates’. You space station may be at 100,100 and your ship is at 1000,1000 thats not near your 800,600 screen rectangle centered at your ship is it?

So the general procedure is:

test if an object is in the viewing rectangle
if it is in the viewing rectangle convert its 100,100 to the screen coordinates.
draw it.

Use a pencil and paper to draw it out, its pretty straight forward.

EDIT: tried to do some ascii art but it didn’t turn out very well, basically you have a floating rectangle in a rectangle.

thanks, I had done that but was still think in math adjustments that were not need. I took out my graph paper this time and drew a scaled map of sector with viewscreen inside and “moved” my viewscreen around. Then figured out that if the object is visible, then find its screen x and y by taking that number and subtracting the viewscreens top left corner coords in true space (sector x and y). When I fly my ship towards the top left corner(approaching my starbase at 100,100, voila! it shows up and scrols nicely with me when I move in any direction.

Thanks a ton nonnus29 and everyone above! back to coding. I’l l post in “Your Games Here” when I have a playable single player demo.

I have gotten a little further along. If anyone has a spare moment to critique the little bit of code I put together or would just like to check it out… go to the link below, the last line of text in red, there is a link to a zip. Sorry, it’s Brinkster and they limit the data transfer rate, so…

thanks!!

http://www22.brinkster.com/mbowles/