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

sdl_getkeystates not working correctly

$
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;

	Object play1;
	
	

	while( quit != true ){
		
		if ( keystates[SDLK_LEFT] == SDL_PRESSED) {
		play1.xvelocity = 5;
			}
		else if (  keystates[SDLK_LEFT] == SDL_RELEASED) {
		play1.xvelocity = 0;
			}	

		

		
		play1.draw_char();
	
	}
	return 0;
}




When i press key down the player moves for one frame and then stops, and i have to continually keep pressing the key.
I have tried many diff options including the standard SDL_Event. nothing seems to work, when i have a key up event. I can change states fine when there all just key down. PLEASE HELP

Viewing all articles
Browse latest Browse all 51036

Trending Articles



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