我在 SFML 中有一个时钟和计时器,它可以测量秒数。我正在尝试在经过一定秒数(特别是 4 秒)后执行下一个操作这是我的代码
#include "stdafx.h"
#include "SplashScreen1.h"
using namespace std;
void SplashScreen1::show(sf::RenderWindow & renderWindow)
{
sf::Clock clock;
sf::Time elapsed = clock.getElapsedTime();
sf::Texture splash1;
sf::SoundBuffer buffer;
sf::Sound sound;
if(!buffer.loadFromFile("sounds/splah1.wav"))
{
cout << "Articx-ER-1C: Could not find sound splah1.wav" << endl;
}
sound.setBuffer(buffer);
if(!splash1.loadFromFile("textures/splash1.png"))
{
cout << "Articx-ER-1C: Could not find texture splash1.png" << endl;
}
sf::Sprite splashSprite1(splash1);
sound.play();
renderWindow.draw(splashSprite1);
renderWindow.display();
sf::Event event;
while(true)
{
while(renderWindow.pollEvent(event))
{
//if(event.type == sf::Event::EventType::KeyPressed
if(elapsed.asSeconds() >= 4.0f)
{
//|| event.type == sf::Event::EventType::MouseButtonPressed)
//|| event.type == sf::Event::EventType::Closed
return;
}
if(event.type == sf::Event::EventType::Closed)
renderWindow.close();
}
}
}
4 秒后它什么也不做。我相信我错误地收集了经过的时间。我知道我的回报是有效的,因为我用鼠标输入尝试过它,它工作得很好。