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

Author Topic: How incorporate more tiles instead of just one?  (Read 1123 times)

0 Members and 1 Guest are viewing this topic.

JTeck

  • Newbie
  • *
  • Posts: 35
    • View Profile
How incorporate more tiles instead of just one?
« 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);
    }
};

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How incorporate more tiles instead of just one?
« Reply #1 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

 

anything