1
Graphics / background image to change to another image after a few seconds.
« on: September 22, 2017, 12:57:50 am »
I want to change the background of the Spirit. However, if I use loadFromFile, I can see only the last image.
....OTL.........
I want the background image to change to another image after a few seconds.
....OTL.........
I want the background image to change to another image after a few seconds.
int main()
{
int i = 0;
std::string link;
char fileName = '0';
std::string str(".jpg");
std::string str0("tutorial/");
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Texture texture;
if (!texture.loadFromFile("images/bg.png"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
// Create a graphical text to display
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event e;
while (window.pollEvent(e)){
// Close window : exit
if (e.type == sf::Event::Closed)
window.close();
if(i<6){
fileName++;
std::cout << fileName << std::endl;
link = str0 + (char)fileName + str;
_sleep(1000);
texture.loadFromFile(link);
i++;
}
}//while (window.pollEvent(e))
window.clear();
// Draw the sprite
window.draw(sprite);
window.display();
}//while (window.isOpen())
return EXIT_SUCCESS;
}
{
int i = 0;
std::string link;
char fileName = '0';
std::string str(".jpg");
std::string str0("tutorial/");
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Texture texture;
if (!texture.loadFromFile("images/bg.png"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
// Create a graphical text to display
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event e;
while (window.pollEvent(e)){
// Close window : exit
if (e.type == sf::Event::Closed)
window.close();
if(i<6){
fileName++;
std::cout << fileName << std::endl;
link = str0 + (char)fileName + str;
_sleep(1000);
texture.loadFromFile(link);
i++;
}
}//while (window.pollEvent(e))
window.clear();
// Draw the sprite
window.draw(sprite);
window.display();
}//while (window.isOpen())
return EXIT_SUCCESS;
}