Sign in to follow this  
Winter dragon

TileMap java side/up scrolling

Recommended Posts

Winter dragon    105
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 :).

Share this post


Link to post
Share on other sites
Narf the Mouse    322
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.

Share this post


Link to post
Share on other sites
Narf the Mouse    322
[quote name='Winter dragon' timestamp='1333805488' post='4929028']
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]
There's a camera; if you watch the tile engine videos at the link, it'll be explained. :)

Share this post


Link to post
Share on other sites
kyanite    395
[quote]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:

[center][i][(offsetX, offsetY), (offsetX + screen width, offsetY + screenHeight)][/i][/center]

which is better demonstrated by this super-quality diagram:
[img]http://i1162.photobucket.com/albums/q523/fenshadow/General/xgrid.png[/img]
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this