Jump to content

  • Log In with Google      Sign In   
  • Create Account


diagonal joystick axes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 hikarihe   Members   -  Reputation: 243

Like
0Likes
Like

Posted 28 February 2013 - 09:08 PM

// 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, 28 February 2013 - 09:11 PM.


Sponsor:

#2 hikarihe   Members   -  Reputation: 243

Like
0Likes
Like

Posted 28 February 2013 - 09:47 PM

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;





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS