• Advertisement
Sign in to follow this  

Landscape moving in a RTS-game.

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new in these forums \o. And this thread might be in the wrong section, so feel free to move this. I've been making a RTS-game for a couple of weeks now, and I've been wondering that how I should move the landscape (when the cursor moves to a corner of the screen)? Do you have any ideas? I've been using a style that is VERY stupid and hopeless: I create an image that is like 10 000 * 10 000 px :] and then just change mapX and mapY -coordinates when the cursor moves to a corner of the screen. And I hope that you would give me an idea to make a better way to do this. Thanks already!

Share this post


Link to post
Share on other sites
Advertisement
First of all, I'ma move this thread to For Beginners... probably a little more appropriate for there.

Now, the big thing: The landscape doesn't move. It's too heavy. [wink] The "camera" moves. So what you have, is a variable describing where in your world the camera is positioned--that is, what point on your world is visible in the center of the screen. When the mouse moves to the edge of the screen, that point starts moving. It's primarily a notational difference, but it's an important one because it makes things much simpler conceptually.

Next: You have correctly intuited that a 10000x10000 pixel image is a bad idea. If nothing else, the fact that it could take up 400 megabytes of texture memory should scare you off. Now, is your landscape tiled? If so, what you do is you simply draw the tiles that are visible, and don't draw the tiles that aren't. Otherwise, you'll need to get into slightly more complicated "paging" setups. What form does the landscape take?

Share this post


Link to post
Share on other sites
Ohh, now I get it. I've heard about those "camera"-thingies before, but not in this case. And yes, my map is tiled. So do you suggest that I should just show the visible tiles and hide all others?

Share this post


Link to post
Share on other sites
Quote:
Original post by nyrhinen
Ohh, now I get it. I've heard about those "camera"-thingies before, but not in this case. And yes, my map is tiled. So do you suggest that I should just show the visible tiles and hide all others?


Exactly, you check before drawing if the current tile is inside the screen area, and do not draw it if it is outside the bounds of the screen, you may also "clip" the tiles that are partially visible.

In order to further optimize drawing, you may want to consider splitting the tilemap into sectors, so if an entire sector is outside the viewport (the screen area), you dont draw any of the tiles in it, avoiding testing each tile individualy, look for a Quadtree structure.

Share this post


Link to post
Share on other sites
In the common case of tiles being stored in a grid structure, you don't even need any fancy quadtree stuff. Just compute the minimum and maximum X and Y for visible tiles, and draw the tiles in that range.

Share this post


Link to post
Share on other sites
Yes, it would definitely speed up things when you render only visible tiles.
Now to calculate if a tile is visible or not on a per-tile base would still be a waste of CPU time, as there are faster methods (such as quad- or octrees) that, although they aren't as precise as a per-tile check, are much faster to execute, so while you'll still render some inivisible tiles the whole process costs less.

I would recommend reading up on such structures before loading maps of that size. :)

// Hmm, it seems I'm a slow poster...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement