there have been a bunch of bugs in your code. It is a working instance, there are a lot of approach of getting this applied. In precept you employ the identical technique as for animating a sprite.
For animations you want to seize the time. Otherwise you won’t be able to calculate the length per body. And you want to retailer the present body in a variable. I put some remark within the instance code beneath.
Btw, in case you are not used to sport loops, take a look on https://gafferongames.com/publish/fix_your_timestep/
#embody
int fundamental(){
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 reduction.ttf")) {
}
window.setFramerateLimit(30);
sf::Textual content gameOver;
gameOver.setFont(myFont);
gameOver.setFillColor(sf::Shade::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::Shade::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 total timing
sf::Clock clock;
sf::Occasion occasion;
// Length to regulate animation velocity
int currentColor = 1;
float length = float();
//the whole lot 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.sort == sf::Occasion::Closed)
window.shut();
if (occasion.sort == sf::Occasion::KeyPressed
&& occasion.key.code == sf::Keyboard::Area){
//shut splash display and begin sport
/*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::Shade(0, currentColor, 0));
}
window.draw(gameOver);
window.draw(playAgain);
window.show();
}
return 0;
}