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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Adriankusiak

Pages: [1]
1
Window / Re: Mouse Button Event not triggering
« on: January 04, 2013, 05:00:09 pm »
Thanks everyone both your answers worked, I thought it would be more efficient to implement Laurent's answer to keep it structured and it works great so thanks very much.

2
Window / Mouse Button Event not triggering
« on: January 04, 2013, 04:27:48 pm »
Hello, I'm writing a small 2D mini-game in which I'm developing a menu. I wrote events to be checked when the mouse is over a button so that specific actions can be triggered but for some reason the mouse event doesn't seem to get triggered at all. When I click over a button nothing happens and I've been checking my code and referencing Google and different tutorials as well as these forums for hours but I can't seem to figure out the problem. I'm using SFML 2.0 and visual studio 11. Any help is much appreciated, thanks.

Here is my code:
        int nCurrentScene=1;
    while (window.isOpen())
    {
                sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

                //Buttons

                sf::Vector2i localPosition = sf::Mouse::getPosition(window);
                sf::FloatRect sStartBnRec = sStartBn.getGlobalBounds();
                sf::FloatRect sExitBnRec = sExitBn.getGlobalBounds();
                sf::Event eMouseClk;
                if(sStartBnRec.contains(localPosition.x,localPosition.y))
                {
                        sStartBn.setTexture(tStartBn_hl);
                        while(window.pollEvent(eMouseClk))
                        {
                                if (eMouseClk.type == sf::Event::MouseButtonPressed)
                                {
                       
                                        if(eMouseClk.mouseButton.button == sf::Mouse::Left)
                                        {
                                                nCurrentScene=2;
                                        }
                                }
                        }
                }
                                else
                {
                        sStartBn.setTexture(tStartBn);
                }

                if(sExitBnRec.contains(localPosition.x,localPosition.y))
                {
                        sExitBn.setTexture(tExitBn_hl);
                        while(window.pollEvent(eMouseClk))
                        {
                                if (eMouseClk.type == sf::Event::MouseButtonPressed)
                                {
                                        if(eMouseClk.mouseButton.button == sf::Mouse::Left)
                                        {
                                                EXIT_SUCCESS;
                                        }
                                }
                        }
                }
                else
                {
                        sExitBn.setTexture(tExitBn);
                }

        window.clear();
                switch (nCurrentScene)
                {
                case 1:
                        window.draw(sMenuBg);
                        window.draw(sExitBn);
                        window.draw(sStartBn);
                        break;
                case 2:
                        window.draw(sLvloneBg);
               
                        break;
                }
       
        window.display();
    }

    return 0;
}

Pages: [1]