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

Author Topic: Small issue with VertexArray based Tilemap  (Read 1113 times)

0 Members and 1 Guest are viewing this topic.

oxez

  • Newbie
  • *
  • Posts: 1
    • View Profile
Small issue with VertexArray based Tilemap
« on: June 15, 2013, 05:59:07 pm »
Hello,

I have a small issue with drawing my tilemap with VertexArray. The map itself draws fine, until I resize my window, then this happens

I don't know where the red line comes from. My texture (.gif file) has a red background, so that explains the color, but I can't tell why the line would display when I resize the window..

My sprites are 8x8, and the tiles on the screen are 32x32, if that's relevant information to the problem

My code is similar to the tilemap example from the website's tutorial

Here's my code that draws the vertices:

for (unsigned int i = 0; i < dimensions.x; ++i) {
        for (unsigned int j = 0; j < dimensions.y; ++j) {
                Tile *tile = &(tiles[i + j * dimensions.x]);

                sf::Vertex *quad = &vertices[(i + j * dimensions.x) * 4];

                quad[0].position = sf::Vector2f(i * block_size, j * block_size);
                quad[1].position = sf::Vector2f((i + 1) * block_size, j * block_size);
                quad[2].position = sf::Vector2f((i+1) * block_size, (j+1) * block_size);
                quad[3].position = sf::Vector2f(i * block_size, (j+1) * block_size);

               
                sf::FloatRect textureRect = sf::FloatRect(tile->getTileType().getTextureRect());
                quad[0].texCoords = sf::Vector2f(textureRect.left, textureRect.top);
                quad[1].texCoords = sf::Vector2f(textureRect.left + textureRect.width, textureRect.top);
                quad[2].texCoords = sf::Vector2f(textureRect.left + textureRect.width, textureRect.top + textureRect.height);
                quad[3].texCoords = sf::Vector2f(textureRect.left, textureRect.top + textureRect.height);
        }
}

And my draw method:

void Map::draw(sf::RenderTarget &target, sf::RenderStates states) const {
        // Draw the stuff.
        states.transform *= getTransform();
        states.texture = &currentTexture;
        target.draw(vertices, states);
}

Thanks, hopefully we can resolve this mistery!

 

anything