Mouse input problems

Started by
0 comments, last by ender7771 18 years, 3 months ago
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 ... ... ...
					}
				}
			}

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?

This topic is closed to new replies.

Advertisement