Can we make an array of sprites in SFML/C++?

久未见 提交于 2019-12-11 08:09:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!