为什么我的sf :: clock在sfml中单独重置
Why is my sf::Clock in SFML resetting by itself?
我正在从事C 的小SFML游戏。我要做的是使用介绍性文字开始游戏,该文字闪烁两种不同的颜色,例如" Arturo Girona Presents"。我通过使用一个内部内部(window.isopen())循环的计数器来使它起作用,但是后来我尝试使用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;
}
时钟没有重置,您根本不会读取新值。; - )
将int timer = clock.getElapsedTime().asMilliseconds();
移入主循环中。
此外,您不需要while (timer < 5000)
循环,尤其是用break
作为最后一个语句。
相关文章:
- 如何将stdout重定向到stderr
- 如何在C++中从两个单独的for循环中添加两个数组
- 用C++在单独的头文件中完成函数体
- 类模板的成员功能的定义在单独的TU中完全专业化
- QTableView:endMoveRows在模型中重置水平页眉大小
- SFML纹理像播放器
- 如何使用单独文件中的派生类访问友元函数对象
- 如何使用AngelScript注册SFML Vector2运算符
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- CoInitialize()在单独的线程上崩溃而不返回
- 如何修复sfml c++代码编译错误
- SFML library: http request
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- 落砂模拟碰撞检测C++和SFML
- 如何从单独的线程控制 SFML 窗口?
- 将 std::cout 从单独线程中的 DLL 重定向到 QTextEdit
- 为什么我的sf :: clock在sfml中单独重置
- SFML 碰撞检测,C++ -> 重置玩家位置
- 如何将 "kill -3 <jvm pid>" 标准输出单独重定向到 linux 和 unix 中的文件?
- 当继承基模板类并将两个类文件放在单独的头文件中时,为什么会出现重定义错误