Sign in to follow this  

Mouse input problems

This topic is 4357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im doing a tic tac toe game with sdl. The player places markers with the mouse, if the PlaceMarker function returns false, that slot is occupied. So the idea was to loop until tehe player manages to place a marker. But when the player tries to place a marker and the function returns false (he cannot) the function is called over and over again generating many log writes. Other than that, it works. THe program waits until the player have placed a marker. I just dont like it calling that function all the time. :P Just when he has clicked again. How am I to do that? Heres the source as it is now:
while(!placed) {
				SDL_PumpEvents();
				SDL_PollEvent(&event);

				if( event.type == SDL_MOUSEBUTTONDOWN ) { 
					if( event.button.button == SDL_BUTTON_LEFT ) { 
						// get mouse position
						SDL_GetMouseState(&MouseX, &MouseY);    // Get the mouse coords
						MouseX = event.button.x; 
						MouseY = event.button.y; 		

						if( MouseX <= FieldPos.X+33 && MouseY <= FieldPos.X+34 && MouseX >= FieldPos.X+0 && MouseY >= FieldPos.Y+0)	{
							if(PlaceMarker(0, 0, "Red"))
								placed = true;
						}

                                                // all other slots ... ... ...
					}
				}
			}

Share this post


Link to post
Share on other sites

This topic is 4357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this