Hi guys, i was reading the tutorials from SFML page, in the tutorial "Designing your own entities with vertex array" they explain that performance depend from number of calls of "draw" function. I created a class to draw batches of entities with different texture, this class inherit from "sf::Drawable" class and, in her method "virtual void draw (RenderTarget &target, RenderStates states) const;" i wrote the next code:
void Menu::draw (RenderTarget &target, RenderStates states) const
{
for (i = 0; i < quantityVertex; i++)
{
states.texture = &textures [i];
target.draw (vertexArray [i[, states);
}
}
this also can be done with the next code inside main game loop
for (i = 0; i < quantitySprites; i++)
window.draw (sprites [i]);
ok, my question is, which is more efficient?? ;D ;D
thank so much for your answers ;), i don't know english ???
Conclusion:
The performance of the function "draw" is given from the number of calls of the function "RenderTarget::draw (const Drawable &drawable, const RenderStates &states), that if someone serves you ;)
As Hapax said VertexArray is for reduce the calls to one for drawing a group of primitives.
The best method could be:
void Menu::draw (RenderTarget &target, RenderStates states) const
{
states.texture = &sprite_sheet ;
target.draw ( vertexArray , states);
}
You can fuse multiple textures in a single sprite sheet , set the primitive type of the VertexArray sf::Quads.
The tutorial and the reference page explain how to apply the sprites and texture coordinates to the primitives.
If you don't understand well the tutorial , you can contact me for PM.