Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

SDL_GetEvent seems flawed

$
0
0
#include "Object.h"
#include "SDL.h"
#include <string>
using namespace std;




SDL_Event event;
Uint8 * keystates = SDL_GetKeyState(NULL);

int main(int argc, char *args[] ){
	bool quit = false;
	bool left = false;

	Object play1;
	
	SDL_Init(SDL_INIT_EVERYTHING);
	

	while( quit != true ){
		
		while( SDL_PollEvent  (&event)){
			if ( event.type == SDL_KEYDOWN){
				switch(event.key.keysym.sym){
					case SDLK_LEFT:
						(left = true);
						break;
					default:
						break;
				}
			
			}
			if ( event.type == SDL_KEYUP){
				switch(event.key.keysym.sym){
					case SDLK_LEFT:
						left = false;
						break;
					default:
						break;
				}
			}
			}
		
		if (left == true ){
			std::cout << "true";
		}
		if (left == false ){
			std::cout << "false";
		}
		play1.draw_char();
	
	}
	return 0;
}



My input loop will not keep a variable at a certain value when i implement key up.
I went ahead and tried this as a test loop. If i press left it becomes true for one frame and then resets back to false right away. I have got to be missing something here, because i have implemented this same input structure on previous games without any problems like this.

Viewing all articles
Browse latest Browse all 51036

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>