私はC++で少しSFMLのゲームに取り組んでいます。私がしようとしているのは、 "Arturo Girona Presents"のような2種類の色を点滅させる紹介テキストでゲームを始めることです。 while(window.isOpen())ループ内でインクリメントされたカウンタを使用して動作させましたが、次に点滅する外観の乱れが少ないかどうかをsf :: Clockを使って試しました。しかし、何らかの理由で、私は明示的に言及していないときに時計が各ループの後にリセットを続けているので、テキスト画面から移行していません。クロックはどのようにリセットされ、どのように修正するのですか?SFMLのsf :: Clockが単独でリセットされるのはなぜですか?
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