If I understood your problem, you're looking for a way to organise sprites and textures instead of creating them one by one? If that's not correct, please expand on this.
For a very simple game, the way you're doing it should be fine, but if you want more organisation, you can sort sprites by putting them in arrays like std::array<sf::Sprite, 15> player1Pieces. Or, for more functionality, create class Piece and put sf::Sprite (or better sf::VertexArray) as a member field, something like this:
class Piece : public sf::Transformable, public sf::Drawable
{
sf::Sprite sprite;
bool captured = false;
void draw(sf::RenderTarget& target, sf::RenderStates states) const override
{
if (captured)
return;
states.transform *= getTransform();
target.draw(sprite, states);
}
public:
void setTexture(const sf::Texture& texture) { sprite.setTexture(texture); }
void capture() { captured = true; }
// add extra functionality here as needed
};
Keep textures outside of class unless there's only one sprite that uses it. If you need to manage huge amount of textures it may be a good idea to make some kind of texture manager, otherwise an array that holds all textures is fine. Keep in mind that Textures must not get out of scope as long as any sprite is using them. So at the end it should look something like this:
int main()
{
enum TextureID { Board, RedPiece, BlackPiece, Dice, Count };
std::array<sf::Texture, TextureID::Count> textures;
textures[Board] .loadFromFile("Board.png");
textures[RedPiece] .loadFromFile("RedPiece.png");
textures[BlackPiece].loadFromFile("BlackPiece.png");
textures[Dice] .loadFromFile("Dice.png");
sf::Sprite board;
board.setTexture(textures[Board]);
sf::Sprite dice;
dice.setTexture(textures[Dice]);
std::array<Piece, 15> player1Pieces;
std::array<Piece, 15> player2Pieces;
for (Piece& piece : player1Pieces)
piece.setTexture(textures[RedPiece]);
for (Piece& piece : player2Pieces)
piece.setTexture(textures[BlackPiece]);
// set starting positions for pieces in a loop
bool gameRunning = true;
while (gameRunning)
{
// game loop
// update game logic
// draw previously created sprites
}
}