I wanted to draw a grid with array of sprites. And I made it work with this code
// loop over each sprite, setting their textures
// grid
for(int i = 0; i < 20; i++)
{
spr[i].setTexture(tex);
spr[i].scale(sf::Vector2f(0.55f, 0.55f));
// 1st row
if(i < 10)
spr[i].setPosition(105.6f * i, y);
// 2nd row
if(i > 10 || i < 20)
spr[i+10].setPosition(105.6f * i, y + 52.8f);
// 3rd row
//if(i > 20 || i < 30)
// spr[i+20].setPosition(105.6f * i, y + 105.6f);
}
Now I want to optimize this code so I can use it more efficiently later. The code brakes if I set spr instead of spr[i+10] in second if loop. Why is this? How can I continue through the array without +10 or whatever next to it?