• Advertisement
Sign in to follow this  

diagonal joystick axes

This topic is 1788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

// handle joystick motion events
case SDL_JOYAXISMOTION:

	// initialize all joystick variables
	eventStates[ JOYSTICK_UP ] = 0;
	eventStates[ JOYSTICK_DOWN ] = 0;
	eventStates[ JOYSTICK_RIGHT ] = 0;
	eventStates[ JOYSTICK_LEFT ] = 0;

	// check left-right movement
	if( event->jaxis.axis == 0 ) 
	{
		// if joystick moving left
		if ( event->jaxis.value < -800 )
		{

			// move left
			eventStates[ JOYSTICK_LEFT ] = 1;
		}

		// if joystick moving right
		else if ( event->jaxis.value > 800 )
		{

			// move right
			eventStates[ JOYSTICK_RIGHT ] = 1;
		}
	}

	// check up-down movement
	if( event->jaxis.axis == 1 ) 
	{
		// if joystick moving up
		if ( event->jaxis.value < -800 )
		{

			// move up
			eventStates[ JOYSTICK_UP ] = 1;
		}

		// if joystick moving down
		else if ( event->jaxis.value > 800 )
		{

			// move down
			eventStates[ JOYSTICK_DOWN ] = 1;
		}
	}

	eventStates[ JOYSTICK_SCALE ] = event->jaxis.value;

	break;

 

my joystick event states are one directional. is it possible to get diagonal states in SDL?

 

something like this: joystick mapping

Edited by hikarihe

Share this post


Link to post
Share on other sites
Advertisement

fixed ^^

 


	// handle joystick motion events
	case SDL_JOYAXISMOTION:

		

		// check left-right movement
		if( event->jaxis.axis == 0 ) 
		{
			// if joystick moving left
			if ( event->jaxis.value < -800 )
			{

				// move left
				eventStates[ JOYSTICK_LEFT ] = 1;
			}

			else
			{

				eventStates[ JOYSTICK_LEFT ] = 0;
			}

			// if joystick moving right
			if ( event->jaxis.value > 800 )
			{

				// move right
				eventStates[ JOYSTICK_RIGHT ] = 1;
			}

			else
			{

				eventStates[ JOYSTICK_RIGHT ] = 0;
			}
		}

		// check up-down movement
		if( event->jaxis.axis == 1 ) 
		{
			// if joystick moving up
			if ( event->jaxis.value < -800 )
			{

				// move up
				eventStates[ JOYSTICK_UP ] = 1;
			}

			else
			{

				eventStates[ JOYSTICK_UP ] = 0;
			}

			// if joystick moving down
			if ( event->jaxis.value > 800 )
			{

				// move down
				eventStates[ JOYSTICK_DOWN ] = 1;
			}

			else
			{

				eventStates[ JOYSTICK_DOWN ] = 0;
			}
		}

		eventStates[ JOYSTICK_SCALE ] = event->jaxis.value;

		break;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement