Thanks, I didn't know about it. Implemented.
Game loop is now:
// main game loop
while(App.isOpen()) {
// event checking
while(App.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
App.close();
break;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
cube.move(0, -1);
if (cube.isColliding(&a))
cube.move(0, +1);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
cube.move(0, +1);
if (cube.isColliding(&a))
cube.move(0, -1);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
cube.move(-1, 0);
if (cube.isColliding(&a))
cube.move(+1, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
cube.move(+1, 0);
if (cube.isColliding(&a))
cube.move(-1, 0);
}
}
App.clear();
// start drawing logic
App.draw(cube.get());
App.draw(a.get());
// end drawing logic
App.display();
}
And all the problems with the movements have been solved. Now what about the framerate? Why is it so low normally and so fast when moving the mouse?