TileMap java side/up scrolling

Started by
4 comments, last by Winter dragon 12 years ago
Hey, im very new game development, but i've tried very basic games like tetris and such, right now im Using LWJGL as i find it much easier to handle things with that library, right now im working on a very basic RTS game for testing purpose. But im having problems with the "camera" im using a tilemap to display my textures but how do i move my camera around in such a map? i've tried searching for it but i can't seem to find it anywhere with a tilemap any feedback would be a great help :).
Advertisement
http://www.youtube.com/user/nickgravelyn/videos?sort=dd&view=0&page=4 - Do you mean a sprite map?

If you mean 3D, the basic idea is similar, but the implementation changes.
I see where my post could have caused some confusion sry, i meant 2D and as i understand it there is no actual camera in 2D.

I see where my post could have caused some confusion sry, i meant 2D and as i understand it there is no actual camera in 2D.

There's a camera; if you watch the tile engine videos at the link, it'll be explained. :)
I see where my post could have caused some confusion sry, i meant 2D and as i understand it there is no actual camera in 2D.[/quote]
Indeed. The typical way to do this is to "scroll" your background as you move, just as you would for a typical sidescroller (platformer) except your view is top-down instead of side-on. A "camera" object helps to keep track of where the player is actually looking, but for 2D purposes it's nothing more than a simplified frustum in the form of a bounding box.

For an RTS, your basic map should be several times the size of the visible screen (for this example only, there's a lot of different ways to break up terrain). Since you mention that you are using a tilemap, I will assume you know how to handle your map data. Thus, at any given point in time, your user's visible position can be calculated as an offset from wherever you consider the map origin (OpenGL considers it at the bottom left of the screen) and the total dimensions, like this:

[(offsetX, offsetY), (offsetX + screen width, offsetY + screenHeight)]



which is better demonstrated by this super-quality diagram:
xgrid.png
where the orange rectangle represents the visible area and the grid itself represents your map broken up into various tiles. Essentially, every time your player moves you draw a different portion of your map. Keep in mind that there are two different coordinate systems in play here: your world coordinates and the local, screen coordinates that you'll use to render. Pretty simple, just ensure you have boundary checks in place so you don't run afoul of out-of-bounds problems, etc.
Thanks for the replies, Specially the last one i got it working with that (really nice) diagram :)

This topic is closed to new replies.

Advertisement