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?
/* 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