SFML community forums

Help => Graphics => Topic started by: JTeck on June 29, 2014, 09:37:10 am

Title: How incorporate more tiles instead of just one?
Post by: JTeck on June 29, 2014, 09:37:10 am
How would I add more than one tile to this vertex map? Haven't been able to find a solution, and my ideas that I have tried are very slim on working.

I want to be able to use more than on tile (like look at an array and replace the numbers with a tile???)

Any clues/help to get me started?
class MapLoader : public TileLoader
{
public:
    MapLoader(void)
    {
        m_mapdata.MapX = 100;
        m_mapdata.MapY = 100;
        m_mapdata.TextureName = "0.gif";
    }
    virtual void AppendTile(int gx, int gy, sf::VertexArray& garr)
    {
        sf::Vertex ver;
        ver.position = sf::Vector2f(gx*16.f, gy*16.f);
        ver.texCoords = sf::Vector2f(0.f, 0.f);
        garr.append(ver);

        ver.position = sf::Vector2f(gx*16.f + 16.f, gy*16.f);
        ver.texCoords = sf::Vector2f(16.f, 0.f);
        garr.append(ver);

        ver.position = sf::Vector2f(gx*16.f + 16.f, gy*16.f + 16.f);
        ver.texCoords = sf::Vector2f(16.f, 16.f);
        garr.append(ver);

        ver.position = sf::Vector2f(gx*16.f, gy*16.f + 16.f);
        ver.texCoords = sf::Vector2f(0.f, 16.f);
        garr.append(ver);
    }
};
Title: Re: How incorporate more tiles instead of just one?
Post by: Jesper Juhl on June 29, 2014, 09:45:23 am
There's an example in the documentation: http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map
In fact, between the tutorials, API docs, wiki and the examples shipped with the source, most things are explained in great detail.
And if that's not enough, there's also a book: http://en.sfml-dev.org/forums/index.php?topic=11992.0