I am working with a simple window that plays some music and shows a red circle. In my code, the code I have to lock the cursor to the center only works with framelimit off. Also, my code for pressing 'esc' to close the window only works with it on. It's confliction. Here's my code:
#include <SFML\System.hpp>
#include <SFML\Config.hpp>
#include <SFML\OpenGL.hpp>
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>
sf::Event event;
sf::Event event2;
sf::Event event3;
int main() {
sf::Music music;
if (!music.openFromFile("meh.flac"))
return -1; // error
music.setLoop(true);
sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");
sf::CircleShape shape(50.f);
shape.setPosition(100, 0);
shape.setFillColor(sf::Color::Red);
sf::Mouse::setPosition(sf::Vector2i(400, 300), window);
music.play();
while (window.isOpen())
{
//input handler loop
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
}
//event handler loop
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
}
while (window.pollEvent(event2)) {
if (event2.type != sf::Event::MouseLeft) {
sf::Mouse::setPosition(sf::Vector2i(400, 300), window);
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
I'm very sensitive about my code, too, so please don't make fun of me for it.