there have been a bunch of bugs in your code. It is a working instance, there are lots of manner of getting this applied. In precept you employ the identical methodology as for animating a sprite.
For animations you could seize the time. Otherwise you will be unable to calculate the length per body. And you could retailer the present body in a variable. I put some remark within the instance code beneath.
Btw, if you’re not used to recreation loops, take a look on https://gafferongames.com/put up/fix_your_timestep/
#embrace
int major(){
int LAYOUT_WINDOW_WIDTH = 800;
int LAYOUT_WINDOW_HEIGHT = 600;
sf::RenderWindow window(sf::VideoMode(LAYOUT_WINDOW_WIDTH, LAYOUT_WINDOW_HEIGHT),
"Tetris 2019 - A New Starting");
sf::Font myFont;
if (!myFont.loadFromFile("cartoon aid.ttf")) {
}
window.setFramerateLimit(30);
sf::Textual content gameOver;
gameOver.setFont(myFont);
gameOver.setFillColor(sf::Coloration::Inexperienced);
gameOver.setStyle(sf::Textual content::Common);
gameOver.setString("GAME OVER!");
gameOver.setCharacterSize(65);
gameOver.setPosition(30, 60);
sf::Textual content playAgain;
playAgain.setFont(myFont);
playAgain.setFillColor(sf::Coloration::Inexperienced);
playAgain.setStyle(sf::Textual content::Common);
playAgain.setString("Press ENTER to play Once more!");
playAgain.setCharacterSize(25);
playAgain.setPosition(80, 235);
// Clock object to measure general timing
sf::Clock clock;
sf::Occasion occasion;
// Length to regulate animation pace
int currentColor = 1;
float length = float();
//all the pieces beneath will get copied into the "processSplash" operate
whereas (window.isOpen()){
// How a lot time since final loop?
sf::Time dt = clock.restart();
length += dt.asSeconds();
whereas (window.pollEvent(occasion)){
if (occasion.kind == sf::Occasion::Closed)
window.shut();
if (occasion.kind == sf::Occasion::KeyPressed
&& occasion.key.code == sf::Keyboard::House){
//shut splash display screen and begin recreation
/*processSplash();*/
}
}
// Animation length per body (0.1f) reached
if (length > 0.01f){
// Restart calculation of the length
length = 0;
// Loop via the animation colours
if (currentColor < 255){
currentColor += 5;
} else {
// Begin from first body if final body reached
currentColor = 0;
}
playAgain.setFillColor(sf::Coloration(0, currentColor, 0));
}
window.draw(gameOver);
window.draw(playAgain);
window.show();
}
return 0;
}