Jump to content
  • Advertisement
Sign in to follow this  
Mizipzor

Mouse input problems

This topic is 4572 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
Advertisement
I dont understand your question. What is wrong with your code? It seems fine now. It only tries to find a blank spot if a mouse click has occurred. What is the problem?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!