hi, please tell me how to do it correctly:
I have a class of a game map. Map size 100x100
inside the class of the game map there is a class DrawTileMap
I draw map like this:
class DrawTileMap : public sf::Drawable, public sf::Transformable
{
public:
void load (const Texture tileset, int ( &TileMap )[100][100]);
void update (int ( &TileMap )[100][100]);
private:
virtual void draw (sf::RenderTarget& target, sf::RenderStates states) const;
VertexArray m_vertices;
Texture m_tileset;
Vector2u tileSize = {64, 64};
};
#include "DrawTileMap.h"
void DrawTileMap::load(const Texture tileset, int ( &TileMap )[100][100])
{
m_tileset = tileset;
m_vertices.setPrimitiveType(sf::Quads);
m_vertices.resize(100 * 100 * 4);
}
void DrawTileMap::update(int ( &TileMap )[100][100])
{
int tu = 0;
int tv = 0;
for(unsigned int x = 0; x < 100; ++x)
for(unsigned int y = 0; y < 100; ++y)
{
switch(TileMap[ x ] [ y ])
{
case 1: tu = 0;tv = 0;break; // Water
case 2: tu = 1;tv = 0;break; // Ground
case 3: tu = 2;tv = 0;break; // Grass
default:tu = 0;tv = 0;break;
}
sf::Vertex* tile64 = &m_vertices[(x + y * 100) * 4];
tile64[0].position = sf::Vector2f(x * tileSize.x, y * tileSize.y);
tile64[1].position = sf::Vector2f((x + 1) * tileSize.x, y * tileSize.y);
tile64[2].position = sf::Vector2f((x + 1) * tileSize.x, (y + 1) * tileSize.y);
tile64[3].position = sf::Vector2f(x * tileSize.x, (y + 1) * tileSize.y);
tile64[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
tile64[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
tile64[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
tile64[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
}
}
void DrawTileMap::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
states.texture = &m_tileset;
target.draw(m_vertices, states);
}
With this approach, I get pictures as pictured on "picture1.png"
but in my tile set there is a smooth transition from grass to earth, 3 sprite
How can I do this to get what is depicted in the "picture2.png" ?