this is the code:
//SpriteBatch.h
#include<SFML\Graphics.hpp>
class SpriteBatch
{
public:
SpriteBatch(void);
~SpriteBatch(void);
void Begin(int Maxvertex);
void Draw(sf::RenderWindow &window,sf::Texture &Texture,sf::Rect<int> &transform,sf::Rect<int> &Source,sf::Color &colora,sf::Color &colorb,sf::Color &colorc,sf::Color &colord,int deep);
virtual void End(sf::RenderWindow &window,sf::Texture &Texture);
sf::VertexArray vertexs;
sf::Texture texture;
int maxvertex;
int cvertex;
};
//SpriteBatch.cpp
void SpriteBatch::Begin(int Max)
{
//Vertex Array
cvertex=0;
maxvertex=Max;
vertexs.setPrimitiveType(sf::Quads);
vertexs.resize(maxvertex);
}
void SpriteBatch::Draw(sf::RenderWindow &window,sf::Texture &tx, sf::Rect<int> &transform,sf::Rect<int> &Source,sf::Color &colora,sf::Color &colorb,sf::Color &colorc,sf::Color &colord,int deep)
{
//Position - Dimension
vertexs[cvertex].position = sf::Vector2f(transform.left, transform.top);
vertexs[cvertex+1].position = sf::Vector2f(transform.left+transform.width, transform.top);
vertexs[cvertex+2].position = sf::Vector2f(transform.left+transform.width, transform.top+transform.height);
vertexs[cvertex+3].position = sf::Vector2f(transform.left,transform.top+transform.height);
//Texture
vertexs[cvertex].texCoords = sf::Vector2f(Source.left,Source.top);
vertexs[cvertex+1].texCoords = sf::Vector2f(Source.left+Source.width, Source.top);
vertexs[cvertex+2].texCoords = sf::Vector2f(Source.left+Source.width,Source.top+Source.height);
vertexs[cvertex+3].texCoords = sf::Vector2f(Source.left, Source.top+Source.height);
//Color
vertexs[cvertex].color = colora;
vertexs[cvertex+1].color = colorb;
vertexs[cvertex+2].color = colorc;
vertexs[cvertex+3].color = colord;
cvertex+=4;
if (cvertex==maxvertex)
{
End(window,tx);
cvertex=0;
}
}
void SpriteBatch::End(sf::RenderWindow &window,sf::Texture &tx)
{
window.draw(vertexs,&tx);
}
I set Maxvertex = 1024