Sign in to follow this  

help with scrolling map that is loaded from txt file

This topic is 4747 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

I got my map to load from txt file but now it wont scroll and it crashes when I try to get it to.
void draw_tiles(void)
{
ifstream MapFile("level1.txt");
int map[48][25];
  
    for(Tileset.y=0; Tileset.y<Tileset.Screen_sizey;Tileset.y++)
    {for(Tileset.x=0; Tileset.x<Tileset.Screen_sizex; Tileset.x++)
    {  //what does this do?
      
      Tileset.scroll_x = Tileset.x + (Tileset.world_camerax/Tileset.Tile_size  );//this allows scrolling on y axis
      Tileset.scroll_y = Tileset.y + (Tileset.world_cameray/Tileset.Tile_size );//this allows scrolling on x axis
      
      
      Tileset.offset_x = Tileset.scroll_x % Tileset.Tile_size;       
      Tileset.offset_y = Tileset.scroll_y % Tileset.Tile_size;   
          
          MapFile >> map[Tileset.scroll_y][Tileset.scroll_x];
          
          Tileset.tiles = map[Tileset.scroll_y][Tileset.scroll_x];
       
    tile_src.left = ((Tileset.tiles - 1)%4) *Tileset.Tile_size;
    tile_src.top =  ((Tileset.tiles - 1) /4) * Tileset.Tile_size ;
    tile_src.right = tile_src.left + Tileset.Tile_size;
    tile_src.bottom = tile_src.top + Tileset.Tile_size  ; 

dstr.left= (Tileset.x*Tileset.Tile_size); //- Tileset.offset_x;
dstr.top= (Tileset.y*Tileset.Tile_size);// - Tileset.offset_y ;
dstr.right = (Tileset.x*Tileset.Tile_size) + (tile_src.right - tile_src.left) ;
dstr.bottom = (Tileset.y*Tileset.Tile_size)  + (tile_src.bottom - tile_src.top)  ;

lpBackBuffer->Blt(&dstr,g_pddTile,&tile_src ,DDBLT_WAIT,NULL);  
                   

}  

 }}  


this is how I load my map and display it. [Edited by - kingpinzs on December 15, 2004 10:00:16 PM]

Share this post


Link to post
Share on other sites
If you try to scroll off the edge of the map(even one pixel) your drawing procedure will try and reference an element in the array holding the map data that does not exist and you'll get null reference errors You need some if statments to check that mapPosX never goes bellow 0 or above LevelWidth-ScreenWidth & mapPosY never goes bellow 0 or above LevelHeight-ScreenHeight.

Does it crash when you sroll a few pixels or when you zoom about the map like a mad man? or just crashes full stop befre you move anywhere.

[Edited by - JDUK on December 16, 2004 6:46:05 AM]

Share this post


Link to post
Share on other sites

This topic is 4747 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.

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