#include <SFML/Graphics.hpp>
#include <string>
class TaggedSprite : public sf::Sprite
{
public:
std::string tag;
};
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "");
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
return EXIT_FAILURE;
std::vector<TaggedSprite> taggedSprites(10);
unsigned int currentSpriteIndex{ 0 };
for (auto& taggedSprite : taggedSprites)
{
taggedSprite.setTexture(texture);
taggedSprite.setPosition(50 * currentSpriteIndex + 10, 10);
++currentSpriteIndex;
}
taggedSprites[0].tag = "word";
taggedSprites[1].tag = "a";
taggedSprites[2].tag = "text";
taggedSprites[3].tag = "string"; // length of 6
taggedSprites[4].tag = "key";
taggedSprites[5].tag = "tag";
taggedSprites[6].tag = "example"; // length of 7
taggedSprites[7].tag = "something"; // length of 9
taggedSprites[8].tag = "else";
taggedSprites[9].tag = "sfml";
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for (const auto& taggedSprite : taggedSprites)
{
if (taggedSprite.tag.length() < 6) // only display taggedSprites that have a tag that is shorter than 6 characters
window.draw(taggedSprite);
}
window.display();
}
return EXIT_SUCCESS;
}