Two Small Coding Questions


Vynx

Member
Joined
May 1, 2006
Messages
253
Nothing major, just need to get this out of the way so I can carry on ;)

1: How do I access the GP2X keys? Someone gave me an include (gp2x_joymap.h), but I can't seem to get it to work.

Code:
if( event.type == GP2X_BUTTON_START )
			{
				quit = true;
			}

It's defined in the include file like so;

Code:
#define GP2X_BUTTON_START		   (8)

2: How do I turn off the mouse in SDL? According to SDL documentation, this should work;

Code:
SDL_ShowCursor(SDL_DISABLE);

( I put this straight after main() )

That's how the documentation suggested it's done anyway, it wasn't too clear to be honest. It's being called before video initialisation though, could that be the problem?

Edit - yes, that was the problem - solved that one. Just need the control mapping problem taken care of now.
 
Tealion posted on Jul 3 2006 at 09:05 PM said:
1. Have you set up an event handler? And included gp2x_joymap.h in your code?

2. I don't think it matters where it's called from

The file is included - and I imagine if it can x out of the window in my windows build with SDL_QUIT, it should be able to quit on the GP2X with GP2X_BUTTON_START
 
Last edited by a moderator:
Have you done all this?

Code:
	SDL_Joystick *joy;
	if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) == -1)
	{
		fprintf(stderr, "Unable to initialise joystick: %s\n", SDL_GetError());
		exit(1);
	}

	if ( SDL_NumJoysticks() > 0)
	{
		joy = SDL_JoystickOpen(0);
	}


	if (joy)
	{
		SDL_JoystickEventState (SDL_ENABLE);
	}
 
Here's what I work with for controls:

Code:
// declare joystick
SDL_Joystick* joystick;
joystick = SDL_JoystickOpen(0);

// button variable
int start;

//input loop
while(!start) {
SDL_JoystickUpdate();
start = SDL_JoystickGetButton(joystick, GP2X_BUTTON_START);
}

- Alex
 
If you want to see some really basic/straight-forward and commented C that shows the joystick use etc then you could have a look at the SRC for the thing i did when i first got my 2X

http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,37,1442

i made sure to include commented code, however poor it is, as i'm of the opinion that if it's homebrew then it should be open source

good luck :)
 
Back
Top