Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fate950

Pages: [1]
1
Graphics / Re: Text file to tilemap, where to start?
« on: October 25, 2022, 08:23:45 pm »
Oh, I see now! I take it this is done in the ifstream loop from my code snippet, right?

2
Graphics / Re: Text file to tilemap, where to start?
« on: October 25, 2022, 07:10:45 pm »
unfortunately, that didn’t work for me, it results in an operator error. I greatly appreciate it though.

what I am trying to wrap my head around is assigning those 0s to chars, no matter what I try, it always results in a blank screen (I assume the txt file is not being read at all). At this point I’m very stumped.

3
Graphics / Re: Text file to tilemap, where to start?
« on: October 24, 2022, 08:17:01 pm »
No, these characters would be mapped to an individual texture.

I ended up following the VertexArray tutorial from the docs, with the addition that it reads from my .txt file to make my map https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php.

My issue at the moment is that, it only accepts my text file if it is composed of numbers https://imgur.com/a/ipgZP73, rather than the aforementioned characters (#,*, . , O) https://imgur.com/a/xUmnALQ

At this point I am only left with turning those numerical values of the textures into chars, so map.txt can be read properly

This is a code snippet of how I process the text file which I suspect is part of the problem
```
bool load(const std::string& tileset, sf::Vector2u tileSize) {
        if (!m_tileset.loadFromFile(tileset))
            return false;
        std::vector<std::vector<int> > tiles;
        std::ifstream stream("map.txt");
        stream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // ignore first line
        for (std::string line; std::getline(stream, line);) {
            tiles.push_back(std::vector<int>());
            std::stringstream ss(line);
            std::copy(std::istream_iterator<int>(ss), std::istream_iterator<int>(), std::back_inserter(tiles.back()));
           ........
        }
         .....
(this is from the sfml vertex array tutorial that I followed)
// define its 4 corners
                quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                // define its 4 texture coordinates
                quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);

From what I've gathered, I need to somehow map these quad positions to the chars I want to use, which is where im at right now

4
Graphics / Text file to tilemap, where to start?
« on: October 23, 2022, 10:55:17 pm »
So, I want to draw a 2d tilemap based on my text file. I followed this https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php from the docs, but the issue here is that my text file isn't composed of numbers, rather they are characters (#,$, . ,@). So a my text file looks something like this.

#########
#.......$..........#
#...............@...#
#...$..............#
#..................#
#....$..........$..#


with # being the walls, $ the loot items,@ as the character, and . as the floor. How would I even do something like this without numbers?

Pages: [1]
anything