Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:13:47+00:00 2026-06-17T20:13:47+00:00

I load the map from a level file which are just numbers corresponding to

  • 0

I load the map from a level file which are just numbers corresponding to a tile in the tilesheet.

Here is the level file

[Map]
0 1 0 0 0 0 0 0
0 0 20 0 0 0 0 0
0 0 0 40 0 0 0 0
0 0 0 0 63 0 0 0
0 0 0 0 0 79 0 0
0 0 0 0 0 0 0 0

And here is the code that interprets it

void LoadMap(const char *filename, std::vector< std::vector <int> > &map)
{
    std::ifstream openfile(filename); 
    if(openfile.is_open())
    {
        std::string line, value;
        int space;

        while(!openfile.eof())
        {
            std::getline(openfile, line);

            if(line.find("[TileSet]") != std::string::npos)
            {
                state = TileSet;
                continue;
            }
            else if (line.find("[Map]") != std::string::npos)
            {
                state = Map;
                continue;
          }

            switch(state)
            {
            case TileSet:
                if(line.length() > 0)
                    tileSet = al_load_bitmap(line.c_str());
                break;
            case Map: 

                std::stringstream str(line);
                std::vector<int> tempVector;

                while(!str.eof())
                {
                    std::getline(str, value, ' ');
                    if(value.length() > 0)
                        tempVector.push_back(atoi(value.c_str()));
                }
                map.push_back(tempVector);
                break;
            }
        }
    }
    else
    {
  }
  }

And this is how it looks
https://i.stack.imgur.com/bPZSG.jpg

Ok so my Tilesheet is 1000 by 200 and it looks like this https://i.stack.imgur.com/Pp4JH.png

How would I make it wrap around to 20 or 40 when putting in 20 or 40 in the map file?

void DrawMap(std::vector <std::vector <int> > map)
{    
    for(int i, j = 0; i < map.size(); i ++)
    {
        for(j = 0; j < map[i].size(); j ++)
        {
          al_draw_bitmap_region(tileSet, map[i][j] * TileSizeX, 0, TileSizeX, TileSizeY, j   * TileSizeX, i * TileSizeX, NULL);
        }
    }
}

Also the TileSizeX and TileSizeY is 50

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:13:48+00:00Added an answer on June 17, 2026 at 8:13 pm

    You need to calculate what cell of the tileset your target tile sits. You have the tileset index. Use a little math, based on the dimensions of the tileset, to determine the col and row of that tile.

    //This is how many columns your tileset can have.
    //You could even dynamically calculate this if you wanted.
    static const int TILESET_COLCOUNT = 20;
    
    void DrawMap(std::vector<std::vector<int> > map)
    {    
        int mapRowCount = map.size();
    
        for (int i = 0; i < mapRowCount; ++i)
        {
            int mapColCount = map[i].size();
    
            for (int j = 0; j < mapColCount; ++j)
            {
                //This is your tileset index in your level map.
                int tilesetIndex = map[i][j];
    
                //The tileset row can be calculated by dividing the tileset index by the number of columns in a tileset row.
                int tilesetRow = floor(tilesetIndex / TILESET_COLCOUNT);
    
                //The tileset column can be calculated by retrieving the remainder of the modulus operation on the total number of columns in a row.
                int tilesetCol = tilesetIndex % TILESET_COLCOUNT;
    
                al_draw_bitmap_region(
                    tileSet, //The tileset
                    tilesetCol * TileSizeX, //multiply the tileset column by the size of a tile to get the source x
                    tilesetRow * TileSizeY, //multiply the tileset row by the size of a tile to get the source y
                    TileSizeX, //width
                    TileSizeY, //height
                    j * TileSizeX, //destination x
                    i * TileSizeX, //destination y
                    NULL //flags
                );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to load data from JDBCTemplate.queryForMap() as it returns the Map Interface? How is
I'm using the following code to load an image and associated image map: <span><%=
Essentially, what I'm trying to do is to load/draw a map from a Tiled
Im trying to load a .txt file into a 2D array which i can
I have an application which needs to load data from a remote server (businesses
I'm trying to load map tiles from an internal SSL server. The SSL certificate's
My aim is to load an OpenLayers map using an external JS file. In
Why drawing a map from google docs takes +50seconds, I have just two columns
I have an Android 13mb application, which displays offline/cached map from sd card. I
I'm making a game in Java. I load the level map processing a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.