I'm having a bad time trying to change the window view by dragging the mouse. I can precisely do that with the method:
void PlayScreen::MenuView(sf::RenderWindow& window)
{
while (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
old_mouse_position = new_mouse_position;
new_mouse_position = sf::Mouse::getPosition(window);
game_view.move(new_mouse_position.x - old_mouse_position.x, new_mouse_position.y - old_mouse_position.y);
}
}
The problem is that the view is updated, (when I release the mouse, it's drawn in the correct position) but it's not drawn as I move the mouse. My gameLoop only draw after all the updates are made, and I was trying to keep the logic that way. Everytihng works fine if I draw inside MenuView while.
my Gameloop is quite simple:
while (main_window.isOpen())
{
while (main_window.pollEvent(event))
{
GameOptions(event);
DrawGame();
}
}
Inside the GameOptions(event) there is a:
if (event.type == sf::Event::MouseButtonPressed)
{
new_mouse_position = sf::Mouse::getPosition(window);
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
MenuView(window);
}
break;
}
I've tried without the while inside the MenuView, but it just don't work.