3
« on: March 31, 2020, 09:34:50 pm »
The problem is that the sprite is hidden, but if you click on it with the mouse , you can interact with it.How do I remove it and why is this happening? Thanks.
sf::RenderWindow window(sf::VideoMode(720, 1820), "Clock");
Clock clock;
Pendulum_clock clock_v1;
sf::Time time = sf::seconds(0.01f);
sf::Clock simple_timer;
int current_screen(0);
while (window.isOpen())
{
sf::Event event;
time = simple_timer.getElapsedTime();
clock_v1.pendulum_swing();
if ((int)time.asSeconds() == 1)
{
switch (current_screen)
{
case 0:clock.arrow_rotation();
break;
case 1:clock_v1.arrow_rotation();
break;
}
simple_timer.restart();
}
while (window.pollEvent(event))
{
if (event.type == sf::Event::MouseButtonPressed)
{
if (event.key.code == sf::Mouse::Left)
{
sf::Vector2i get_pixel = sf::Mouse::getPosition(window);
sf::Vector2f position = window.mapPixelToCoords(get_pixel);
if (clock.s_clock.getGlobalBounds().contains(position)) // here
{
++current_screen;
if (current_screen > 1){ current_screen = 0; }
switch (current_screen)
{
case 0:clock.initialization_by_the_system_clock(); break;
case 1:clock_v1.initialization_by_the_system_clock(); break;
}
}
if (clock_v1.s_pendulum.getGlobalBounds().contains(position)) // and here
{
std::cout << "click\n";
}
}
}
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
switch (current_screen)
{
case 0:window.draw(clock); break;
case 1:window.draw(clock_v1); break;
}
window.display();
}
return 0;
}