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 - Banana Snooters

Pages: [1]
1
Graphics / Help understanding "TileMap" Class in tutorial
« on: June 28, 2014, 01:05:19 am »
Hello, I'm starting to learn SFML 2.0 and have been working through the tutorials. I'm trying to understand the tilemap example: http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php
I've implemented it into my project and it works perfectly, but there's a part that I don't understand...

// populate the vertex array, with one quad per tile
        for (unsigned int i = 0; i < width; ++i)
            for (unsigned int j = 0; j < height; ++j)
            {
                // get the current tile number
                int tileNumber = tiles[i + j * width];

                // find its position in the tileset texture
                int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                // get a pointer to the current tile's quad
                sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

so where it says "//find its position in tileset texture", can someone explain what exactly is going on here?
my project has 20x20 pixel tiles, and the texture is 640x400. So 640 pixels/20 pixels =32 pixels. but how does tileNumber / or % by 32 find the position of the tile in the texture??

I  understand how tu and tv are used later when assigning texCoords to the verticies ( they seem to act as multipliers of the tilesize.x), but how do the definitions of tu and tv result in integers corresponding to the location of tile in the texture??

Thanks for any help you can provide me!

Pages: [1]