#include <iostream>
#include <SFML/Graphics.hpp>
const int WIDTH = 1024;
const int HEIGHT = 860;
const int W_CENTER = WIDTH / 2;
const int H_CENTER = HEIGHT / 2;
int main()
{
sf::RenderWindow window(sf::VideoMode(1024, 860), "Asteroids");
sf::RectangleShape rectangle(sf::Vector2f(50.0f, 50.0f));
rectangle.setFillColor(sf::Color(200, 0, 200));
rectangle.setPosition(sf::Vector2f(W_CENTER, H_CENTER));
rectangle.setOrigin(25, 25);
float angle = 1;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
rectangle.rotate(-angle);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
rectangle.rotate(angle);
}
}
window.clear(sf::Color::Black);
window.draw(rectangle);
window.display();
}
return 0;
}
Very simple, but if I mouse the mouse around at the same time I press either the Left or Right key, the rotation goes nuts and you see that I don't have any work to do with the mouse, just with the keys. Maybe I am missing something, anyway, makes no snese tp me.
Thank you!