SFML 停止或删除时钟
SFML Stop or delete clock
是否可以在 SFML 中停止或删除时钟?我正在学习 SFML,我做了矩形变大,直到 4 秒过去然后它重置。但现在我正在考虑做类似的事情,但我不想重置矩形大小,而是想保留它在 4 秒内得到的矩形大小,然后我想在前一个矩形旁边绘制下一个矩形。但要做到这一点,我需要以某种方式停止创建的时钟或冻结它,否则第一个矩形只会变得更大。可以吗?
sf::RenderWindow window(sf::VideoMode(1800, 800), " window ");
sf::Clock timer;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
} //while
window.clear();
sf::RectangleShape shape(sf::Vector2f(timer.getElapsedTime().asSeconds()*50,100));
if (timer.getElapsedTime().asSeconds() > 4)
{
timer.restart();
}
shape.setPosition(sf::Vector2f(100, 400));
shape.setFillColor(sf::Color(150,150,150));
window.draw(shape);
window.display();
}
一种方法可能是这样
sf::RenderWindow window(sf::VideoMode(1800, 800), " window ");
sf::Clock timer;
sf::RectangleShape shape(sf::Vector2f(timer.getElapsedTime().asSeconds()*50,100));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
} //while
window.clear();
if (shape.getSize().x < 200)
shape.setSize(sf::Vector2f(std::min(timer.getElapsedTime().asSeconds()*50, 200.f), 100));
shape.setPosition(sf::Vector2f(100, 400));
shape.setFillColor(sf::Color(150,150,150));
window.draw(shape);
window.display();
}
是否可以在 SFML 中停止或删除时钟?我正在学习 SFML,我做了矩形变大,直到 4 秒过去然后它重置。但现在我正在考虑做类似的事情,但我不想重置矩形大小,而是想保留它在 4 秒内得到的矩形大小,然后我想在前一个矩形旁边绘制下一个矩形。但要做到这一点,我需要以某种方式停止创建的时钟或冻结它,否则第一个矩形只会变得更大。可以吗?
sf::RenderWindow window(sf::VideoMode(1800, 800), " window ");
sf::Clock timer;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
} //while
window.clear();
sf::RectangleShape shape(sf::Vector2f(timer.getElapsedTime().asSeconds()*50,100));
if (timer.getElapsedTime().asSeconds() > 4)
{
timer.restart();
}
shape.setPosition(sf::Vector2f(100, 400));
shape.setFillColor(sf::Color(150,150,150));
window.draw(shape);
window.display();
}
一种方法可能是这样
sf::RenderWindow window(sf::VideoMode(1800, 800), " window ");
sf::Clock timer;
sf::RectangleShape shape(sf::Vector2f(timer.getElapsedTime().asSeconds()*50,100));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
} //while
window.clear();
if (shape.getSize().x < 200)
shape.setSize(sf::Vector2f(std::min(timer.getElapsedTime().asSeconds()*50, 200.f), 100));
shape.setPosition(sf::Vector2f(100, 400));
shape.setFillColor(sf::Color(150,150,150));
window.draw(shape);
window.display();
}