问题
My question is very simple. Can we make an array of sprites or images in SFML. For example:
int myArray[] = {1, 2, 3};
Consider index number one, two and three are three different images. How can we do it? Can anyone explain with some code example?
回答1:
Try
std::vector<sf::Sprite> myArray;
or
sf::Sprite myArray[3];
Check out the answer of this question. The main part is:
// Create a texture
sf::Texture invaderTexture;
// Load image file into that texture
invaderTexture.loadFromFile("images/invaders.png");
// Create a vector of 10 sprites initialised with the texture above
std::vector<sf::Sprite> invaderSprites(10, sf::Sprite(invaderTexture));
来源:https://stackoverflow.com/questions/20933134/can-we-make-an-array-of-sprites-in-sfml-c