This topic is now archived and is closed to further replies.


Isometric map scrolling

Recommended Posts

jarett    122
Hi all, I took a quick peek through the archives, but didn''t see anything directly related to my topic. Feel free to point me back to a specific thread if I''ve missed one. At present, my engine limits the size of the map to that which can be drawn on the screen. A 1-dimensional array keeps track of all of the id. numbers for each tile. What I want to do allow the map to scroll as the character (or camera) moves - essentially allowing "unlimited" map size. Hopefully I made myself intelligible. Cheers, Jarett

Share this post

Link to post
Share on other sites
jaxson    127
If you can afford it, I''d recommend getting TANSTAAFL''s book. He describes many isometric concepts very well including scrolling. However, if you want the free version (ie. mine) you can have a larger map but only draw the visible portion of the map every frame. One way you can do this is to just draw everything as before and clip tiles that aren''t on the screen (negative coords, etc).
This isn''t terribly efficient but is pretty easy. The best way is to only draw the tiles that are on the screen (or partially on the screen) but this can get tricky and takes a while to explain here. Basically, you need to figure out what tiles appear on the screen or just off the edges and draw only those and nothing else.

Wish I could give a more detailed explanation but it''s late and I''m off to bed. Good luck!

Share this post

Link to post
Share on other sites
henryx    128
Here''s some code from a game I did a while ago which might give you some ideas:


void CBackground::AdjustScreenPosition(void)
int x = Player.x;
int y = Player.y;
//int x = Enemy[0].x;

//int y = Enemy[0].y;

// adjust screen position *******

//if Player is more than half a screen away from left edge

if ( (x + SCNW/2)>SCNW ) Screen.x = x - SCNW/2;
else Screen.x = 0;

//if Player is more than half a screen away from top edge

if ( (y + SCNH/2)>SCNH ) Screen.y = y - SCNH/2;
else Screen.y = 0;

//if Player is closer than half a screen away from right edge

if (x > (TILEDX * MAPDX - SCNW/2 )) Screen.x = TILEDX * MAPDX - SCNW;

//if Player is closer than half a screen away from bottom edge

if (y > (TILEDY * MAPDY - SCNH/2 )) Screen.y = TILEDY * MAPDY - SCNH;


Screen.x, Screen.y are is the position of the top left hand corner of the visible screen within the background map.

Player.x, Player.y is the position of the main character of focus within the map, (map coordinates).

This function defines the portion of the map to be drawn which is basically the bit of the map round the player.


HRESULT CBackground::DrawTiles(void)

float PiBy2 = D3DX_PI/2.0f;
int tx, ty; // tiles starting pos

int LenX, LenY; //number of tiles to draw

int CountX, CountY; //counters

tx = Screen.x>>SHIFT; ty = Screen.y>>SHIFT;
LenX = (SCNW>>SHIFT)+1; LenY = (SCNH>>SHIFT)+2;

// clip drawing to within tile map dimensions

if (tx<0) tx=0;
if (ty<0) ty=0;
if ((tx+LenX)>MAPDX) LenX = MAPDX - tx;
if ((ty+LenY)>MAPDY) LenY = MAPDY - ty;

//TILEDX/2 since the ddrawing point of tile is it''s midpoint

//Draw Tiles Tiles

for(CountY=0; CountY < LenY ; ++CountY)
Position.y = (float)(CountY*TILEDY - (Screen.y%TILEDY));
for(CountX=0; CountX<LenX ; ++CountX)
Position.x = (float)(CountX*TILEDX - (Screen.x%TILEDX));
Area = Tile[ty+CountY][tx+CountX].Area;
Rot = Tile[ty+CountY][tx+CountX].Rot;
Hr = DrawTexture();

The above functions draws the background tiles to the screen. Note that SHIFT = 5 and is just a quick way of dividing by 32 which is the pixel dimensions of the tiles.

Hope this gives some pointers,


Share this post

Link to post
Share on other sites