Laurent, so do I have to keep one texture in a tileset instance(for example) and keep pointers to this texture in the tiles?
No need to store references to the texture, sf::Sprite already does that. All you need to store for a tile (with your current design) is a sf::Sprite, ready to be drawn.
If so, how do I use a part of a texture?
sprite.setTextureRect(sf::IntRect(left, top, width, height));
Is there any examples? I've never done such things before, so example would be very helpful and I believe it will really boost the perfomance.
The corresponding tutorial is not online yet, and there's no official example that uses a vertex array yet. But if you search on this forum, and probably on the wiki, you should find interesting stuff.
Because it's not very hard, let's try a brief explanation.
If you have a sprite:
sf::Sprite tile;
tile.setTexture(&tileset);
tile.setPosition(x, y);
tile.setTextureRect(sf::IntRect(tx, ty, w, h));
window.draw(tile);
Then you can easily create a similar entity with a vertex array:
sf::VertexArray tile(4, sf::Quads);
// first Vector2f is the position, second Vector2f is the texture coordinates
tile[0] = sf::Vertex(sf::Vector2f(x, y), sf::Vector2f(tx, ty));
tile[1] = sf::Vertex(sf::Vector2f(x + w, y), sf::Vector2f(tx + w, ty));
tile[2] = sf::Vertex(sf::Vector2f(x + w, y + h), sf::Vector2f(tx + w, ty + h));
tile[3] = sf::Vertex(sf::Vector2f(x, y + h), sf::Vector2f(tx, ty + h));
window.draw(tile, &tileset);
FYI, that's more or less how sf::Sprite is implemented internally.
Now put more than 1 quad into your vertex array:
sf::VertexArray map(sf::Quads, 4 * nbTilesX * nbTilesY);
for (int i = 0; i < nbTilesX; ++i)
for (int j = 0; j < nbTilesY; ++j)
{
float tx = ... // from your loaded map info
float ty = ... // from your loaded map info
map[(i + j * nbTilesX) * 4 + 0] = sf::Vertex(sf::Vector2f(i * w, j * h), sf::Vector2f(tx, ty));
map[(i + j * nbTilesX) * 4 + 1] = sf::Vertex(sf::Vector2f((i + 1) * w, j * h), sf::Vector2f(tx + w, ty));
map[(i + j * nbTilesX) * 4 + 2] = sf::Vertex(sf::Vector2f((i + 1) * w, (j + 1) * h), sf::Vector2f(tx + w, ty + h));
map[(i + j * nbTilesX) * 4 + 3] = sf::Vertex(sf::Vector2f(i * w, (j + 1) * h), sf::Vector2f(tx, ty + h));
}
window.draw(map, &tileset);
That's it, a super optimized static tile map