strange input error

This is a discussion on strange input error within the Game Programming forums, part of the General Programming Boards category; ok i seem to have coded somthing wrong? i am making a basic pong style game and have the keys(a ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    118

    strange input error

    ok i seem to have coded somthing wrong?
    i am making a basic pong style game and have the keys(a +z) (up arrow + down arrow) for the input to move the pong paddles.
    it works at first but after i have pressed the (a or z) key any key after that moves that paddle evan esc.
    here is an example if i press up the left paddle goes up now i press esc it moves up more. then i press z it moves down. press up arrow moves down again.

    here is the part of code that handles the key presses sorry if its messy.
    Code:
    //While there's events to handle
            while( SDL_PollEvent( &event ) )
            {
                //If a key was pressed
                if( event.type == SDL_KEYDOWN )
    			{// left paddle keypress
    				if(event.key.keysym.sym == SDLK_a)
    				{
    					leftPaddle.yVel = -10;
    				}
    				else if(event.key.keysym.sym == SDLK_z)
    				{
    					leftPaddle.yVel = 10;
    				}
    			
    				
    			
    			
    //rightpaddle keypresses
    			else if(event.key.keysym.sym == SDLK_UP)
    				{
    					rightPaddle.yVel = -10;
    				}
    			
    			else if(event.key.keysym.sym == SDLK_DOWN)
    				{
    					rightPaddle.yVel = 10;
    				}
    				leftPaddle.p_PaddleMove();
    				 rightPaddle.p_PaddleMove();
    			}
         }
    edit:
    ok sorry i finnaly relized what i did wrong
    Code:
      if( SDL_PollEvent( &event ) )
    		{
               //If a key was pressed
                if( event.type == SDL_KEYDOWN )
    			{       // left paddle keypress
    				if(event.key.keysym.sym == SDLK_a)
    				{
    					leftPaddle.yVel = -10;
    					leftPaddle.p_PaddleMove();
    			
    				}
    				else if(event.key.keysym.sym == SDLK_z)
    				{
    					leftPaddle.yVel = 10;
    					leftPaddle.p_PaddleMove();
    			
    				}
    and so on
    Last edited by thestien; 12-26-2007 at 11:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21