为什么我的SFML中的sf::时钟会自动重置? 我正在做一个C++的小SFML游戏。我想做的是在游戏开始时用一个介绍性的文本闪烁两种不同的颜色,比如“Arturo Girona Presents”。我使用了一个在while(window.isOpen())循环中递增的计数器,然后我尝试使用一个sf::Clock来查看它是否使闪烁看起来不那么随机。然而,由于某些原因,时钟在每次循环后都会一直重置,而我也没有明确告诉它,因此它不会从文本屏幕转换。时钟是如何自行复位的?我该如何修理它? 这是我的while循环: 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; } int count=0; sf:时钟; int timer=clock.getElapsedTime().asmillseconds(); while(window.isOpen()) { 计数++; sf::事件; while(window.pollEvent(事件)) { 如果(event.type==sf::event::Closed) window.close(); } window.clear(); 同时(定时器

为什么我的SFML中的sf::时钟会自动重置? 我正在做一个C++的小SFML游戏。我想做的是在游戏开始时用一个介绍性的文本闪烁两种不同的颜色,比如“Arturo Girona Presents”。我使用了一个在while(window.isOpen())循环中递增的计数器,然后我尝试使用一个sf::Clock来查看它是否使闪烁看起来不那么随机。然而,由于某些原因,时钟在每次循环后都会一直重置,而我也没有明确告诉它,因此它不会从文本屏幕转换。时钟是如何自行复位的?我该如何修理它? 这是我的while循环: 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; } int count=0; sf:时钟; int timer=clock.getElapsedTime().asmillseconds(); while(window.isOpen()) { 计数++; sf::事件; while(window.pollEvent(事件)) { 如果(event.type==sf::event::Closed) window.close(); } window.clear(); 同时(定时器,c++,sfml,C++,Sfml,在主循环内移动int timer=clock.getElapsedTime().asmillseconds(); 此外,您不希望使用while(计时器

在主循环内移动
int timer=clock.getElapsedTime().asmillseconds();


此外,您不希望使用
while(计时器<5000)
循环,尤其是最后一个语句是
中断。

可以
谢谢!移动那一行解决了我的问题,但我必须保持中断;否则当我运行它时,程序将停止响应。@ArturoGirona:有了这个中断,你的
while
实际上是一个
,如果
,它不会循环没关系,这是你的意图吗?