我正在用C++編寫一個小型的SFML遊戲。我想要做的就是用閃亮兩種不同顏色的介紹性文字開始遊戲,比如「Arturo Girona Presents」。我通過使用在while(window.isOpen())循環內部增加的計數器來實現它的工作,但後來我嘗試使用sf :: Clock來查看它是否使閃爍的外觀不那麼隨意。但是,由於某些原因,當我沒有明確地告訴它時,時鐘在每個循環後都保持重置,所以它不會從文本屏幕轉換。時鐘如何自行復位以及如何修復? 這裏是我的while循環:爲什麼我的sf :: SFML中的時鐘自己重置?
int count = 0;
sf::Clock clock;
int timer = clock.getElapsedTime().asMilliseconds();
while (window.isOpen())
{
count++;
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
while (timer < 5000)
{
if (timer < 200 && introText1.getColor() == sf::Color::Red)
{
introText1.setColor(sf::Color::White);
window.draw(introText1);
window.display();
}
if (timer < 200 && introText1.getColor() == sf::Color::White)
{
introText1.setColor(sf::Color::Red);
window.draw(introText1);
window.display();
}
break;
}
if (timer == 5000) {
window.clear();
window.draw(door);
window.draw(doorWindow1);
window.display();
}
cout << timer << endl;
if (timer > 0)
cout << "Time is moving" << endl;
}
'cout << timer << endl;'是否顯示相同的數字?你似乎沒有改變這個循環中的任何地方 – doctorlove