Detecting Button Input With Sdl


PSyMastR

\m/O__O\m/
Joined
Sep 14, 2005
Messages
2,968
Website
Visit site
Ok, Im using an SDL event to detect button input. This is in the top of my program:

Code:
#define GP2X_BUTTON_UP              (0)
#define GP2X_BUTTON_DOWN            (4)
#define GP2X_BUTTON_LEFT            (2)
#define GP2X_BUTTON_RIGHT           (6)
#define GP2X_BUTTON_UPLEFT          (1)
#define GP2X_BUTTON_UPRIGHT         (7)
#define GP2X_BUTTON_DOWNLEFT        (3)
#define GP2X_BUTTON_DOWNRIGHT       (5)
#define GP2X_BUTTON_CLICK           (18)
#define GP2X_BUTTON_A               (12)
#define GP2X_BUTTON_B               (13)
#define GP2X_BUTTON_X               (14)
#define GP2X_BUTTON_Y               (15)
#define GP2X_BUTTON_L               (10)
#define GP2X_BUTTON_R               (11)
#define GP2X_BUTTON_START           (8)
#define GP2X_BUTTON_SELECT          (9)
#define GP2X_BUTTON_VOLUP           (16)
#define GP2X_BUTTON_VOLDOWN         (17)

This code is basically setup for the GP2x, but it doesn't seem to work right. I also have the key input for the PC, and am wondering what the call is for the gp2x.

Code:
int main( int argc, char **argv )
{
	SDL_Event	event;
	Uint8     *keystate;

	// Initialise SDL and Joystick
	SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
	SDL_ShowCursor (0);  //Removes the mouse cursor
	SDL_JoystickOpen(0);	//Opens up the Joystick for use
	
	// Initialize the screen / window 
	screen = SDL_SetVideoMode( 320, 240, 8, SDL_SWSURFACE

	// Main loop
	while (1)
	{
  
  // Handle events (key input, mainly)
  while(SDL_PollEvent(&event))
  {
  	switch(event.type)
  	{
    case SDL_JOYBUTTONDOWN:
    	switch(event.jbutton.button)
    	{
      case GP2X_BUTTON_START: // Start pressed
      	game.running = 0;
      	break;
    	}
    	break;
  	}
  }
  // If we have been told to exit, do so now
  if (game.running == 0)
  {
  	break;
  }
  
  
  keystate = SDL_GetKeyState( NULL );
  
  SDL_Delay( 30 );
	}

	// Victory!
	return cleanUp( 0 );
}

Thanks alot
-Jeff (PSy)
 
So... I guess nobody knows what the correct call for converting a program that contains keyboard input, to replace it with button input? Or is that correct (sorry, the wiki was very unclear in that part)
 
No.

I considered answering here before, but halfway through the reply realized it was too sarcastic to be any good, and my postings tend to be a bit negative anyway. I think mostly this was triggered because you post lots of source code (where you could have cut out most of the defines), but don't ask a proper question, or even give the needed boundary conditions. You just indicate 'it doesn't work'. And sign with a annoying picture in your sig, and oh you have a screen name that implies masterfulnes.. All in all just added up to me thinking 'I'll pass on this one' Looks liek everyone else thought along those lines too.

For us to help in a meaningful way, please state things like what version of the sdl-libs are you using. Where in the build proces do things go wrong, what are the errors and the commands that triggered them? What did you try yourself already, and didn't help, or worsned things (and in what way). Think about what we'd have to know to help you. It's extremely frustrating to have to ask for more information, then wait 24 hours to get a few drops more, etc.

90% of this kind of problem can be solved without us ever firing up a compiler, IF you'd provide more information (and NO, we're not supposed to ask you for more information, you, as the question-asker, should think of providing it, or you'll end up on the bottom of the stack... Remember, none of us get paid to help you!)

Of the other 10%, 90% of the things just work if we were to try to duplicate the problem, because we'd do the right thing where you'd made your booboo. Again, we wouldn't be able to help you effectively.

So, go back to your orignal problem, add a few printf statements to see if the program flows the way you expect it to, none of the functions return an error, and what are the raw values you get returned in the events. Formulate a proper question with as much relevant detail as you can, basically show that you're putting in your part.

I'm pretty sure you'd get help then..


P.
 
Forget it, I solved it myself by looking at the sources of other projects.

My question was, are there any special input methods, that are needed for the buttons of the GP2x, such as storing the inputted key (on a computer) into a Uint8, but I solved it myself. Oh, and my username comes from was long ago when I did master the psychic powers of a game, hence psymastr. (psymaster was too long)
 
It's bad form to ask a question without doing any research yourself, where people have to come right back at you with questions for more information, but it's even worse form to ask a question, and not to come back after it's solved with a simple write-up of what you did wrong, and what was the solution. If someone else has a similar problem, does a search, and finds this topic, he's going to be frustrated because there is no answer, just a 'Ah, solved it myself...'

No need to defend your username. I just pointed out what were the reasons for me not to try to answer your post, and that was just one of the proverbial 'feathers'.


P.
 
Ok, I see.

Anyway, here was my problem:

I have used SDL before in making computer games.
I wanted to use the GP2X button mapping and store it in a variable.

I didn't know how to do that, and posted my code so someone could tell me.

I basically scrapped the whole thing, and rewrote it.
I figured the definitions up top relate the word to the value, so instead, I scrapped that and just used the values instead storing it in a:
Code:
Uint8 *ButtonPress
Thus, I was able to use my existing code without rewriting the entire program over to allow for GP2x button input.

Also, Sorry if I sounded rude, I didn't mean it.
 
Back
Top