I made an extremely simple "game", however, it exits when I let the mouse enter the window. Here is the code:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::Vector2i screenDimensions(800, 600);
enum Direction {Down, Left, Right, Up};
float frameCounter = 0, switchFrame = 100, frameSpeed = 500;
sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Picking Stick!");
window.setKeyRepeatEnabled(false);
sf::Vector2i source (1, Down);
sf::Clock clock;
sf::Sprite pSprite;
sf::Texture pTexture;
if(!pTexture.loadFromFile("pTexture.png"))
std::cout << "Error" << std::endl;
else
pSprite.setTexture(pTexture);
sf::Sprite background;
sf::Texture backgroundTexture;
if(!backgroundTexture.loadFromFile("Wood.png"))
std::cout << "Error" << std::endl;
background.setTexture(backgroundTexture);
background.setScale((screenDimensions.x / 500.0f), (screenDimensions.y / 375.0f));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed);
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
source.y = Direction::Up;
pSprite.move(0, -.03f);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
source.y = Direction::Down;
pSprite.move(0, .03f);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
source.y = Direction::Left;
pSprite.move(-.03f, 0);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
source.y = Direction::Right;
pSprite.move(.03f, 0);
}
frameCounter += frameSpeed * clock.restart().asSeconds();
if (frameCounter >= switchFrame)
{
frameCounter = 0;
source.x++;
if(source.x * 32 >= pTexture.getSize().x)
source.x = 0;
}
pSprite.setTextureRect(sf::IntRect(source.x * 32, source.y *32, 32, 32));
window.draw(background);
window.draw(pSprite);
window.display();
window.clear();
}
return 0;
}
Thanks a lot in advance