Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Program exits when I hover mouse over window.  (Read 2037 times)

0 Members and 1 Guest are viewing this topic.

wizh

  • Newbie
  • *
  • Posts: 19
    • View Profile
Program exits when I hover mouse over window.
« on: June 05, 2013, 06:14:01 pm »
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 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Program exits when I hover mouse over window.
« Reply #1 on: June 05, 2013, 06:52:56 pm »
if (event.type == sf::Event::Closed) ;
Laurent Gomila - SFML developer

wizh

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Program exits when I hover mouse over window.
« Reply #2 on: June 05, 2013, 09:26:47 pm »
?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Program exits when I hover mouse over window.
« Reply #3 on: June 05, 2013, 09:43:55 pm »
It's in red and bold :P

The semicolon is wrong.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

wizh

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Program exits when I hover mouse over window.
« Reply #4 on: June 05, 2013, 09:56:45 pm »
Facepalm.

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Program exits when I hover mouse over window.
« Reply #5 on: June 10, 2013, 08:16:25 pm »
It happens to the best of us, don't even fret.   ;D

 

anything