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 - murkinmouse

Pages: [1]
1
General / Why does my code register two mouse clicks per click?
« on: March 21, 2012, 01:58:59 pm »
thank you! :)

2
General / Why does my code register two mouse clicks per click?
« on: March 21, 2012, 12:37:13 pm »
Hi,
When I run the following code & click the screen any number of times I get one undefined mouse click to start with then for each click I get a duplicate one.
 
Why is this?


 
Code: [Select]

/* main.cpp */
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <string>
using namespace std;

int main( void )
{
     // set gameWindow parameters
    sf::RenderWindow gameWindow( sf::VideoMode( 1024, 600, 32 ), "Adam's Fantasy", sf::Style::Fullscreen );

     // fill gameWindow with black background
    gameWindow.Clear();

     // include buttonOne.jpg
    sf::Image Image;
    Image.LoadFromFile( "buttonOne.jpg" );
    sf::Sprite buttonOne;
    buttonOne.SetImage( Image );
    gameWindow.Draw( buttonOne );

     // include buttonTwo.jpg
    Image.LoadFromFile( "buttonTwo.jpg" );
    sf::Sprite buttonTwo;
    buttonTwo.SetImage( Image );
    buttonTwo.SetPosition( 512.f, 300.f );
    gameWindow.Draw( buttonTwo );

     // display the game window
    gameWindow.Display();

     // begin interaction loop
    while ( gameWindow.IsOpened() )
    {
        sf::Event Event;
        /* while ( gameWindow.GetEvent( Event ) )
        { */
             // Press escape key to close the game
            if ( ( Event.Type == sf::Event::KeyPressed ) && ( Event.Key.Code == sf::Key::Escape ) )
                gameWindow.Close();

             // Left click
            if ( Event.MouseButton.Button == sf::Mouse::Left )
            {
                cout << "The left mouse button was clicked at " << Event.MouseButton.X << ", " << Event.MouseButton.Y << endl;
                    if ( Event.MouseButton.X >= 512 && Event.MouseButton.X <= 822 )
                    {
                        if ( Event.MouseButton.Y >= 300 && Event.MouseButton.Y <= 460 )
                            cout << "You clicked the picture" << endl;
                    } // end if
            } // end if
        /* } // while events are recieved */
    } // while gameWindow.IsOpened
} // end main
//////////////////////////////////////////////////////////////////////////////////////////////////////////


Thanks

Pages: [1]
anything