Jump to content
  • Advertisement
Sign in to follow this  
tashaklikedi

I need help with joystick handling

This topic is 2117 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

Hi, I'm trying to create a double dragon - like game, and I'm trying to implement a joystick.

The problem is that until now I programmed relative to the SDL 's keyboard event handling system, which involves the key states "keydown" when a key is pressed, and "keyup" when a key is released. But I can't find a way to do the keyup part with the SDL joystick functions.

The reason I want to use this is that when you double tap a horizontal direction key, the character runs. For that I developed a counter system, in which when I release the direction key, there is a counter that is incremented and that says that I pressed forward once.

now I will paste the code here.

this is the key release function for the left key:
[source lang="cpp"]
case SDLK_LEFT: {
moveLeft = false;
runCounterLeft++;
runCounterRight = 0;

}
break;[/source]

and this is the function that activates the run function:

[source lang="cpp"]void CNinja::runToggle()
{


if(runToggleSwitch) // the counter is at most at 1
{
if(runCounterRight == 1)
{

{
runStart = SDL_GetTicks(); //time offset for the last released direction key
runToggleSwitch = false;
}
}
if(runCounterLeft == 1)
{

{
runStart = SDL_GetTicks();
runToggleSwitch = false;
}
}


}

if(runStart + 200 < SDL_GetTicks()) // resetting the counter states if two taps are delayed too much
{
runToggleSwitch = true;
runCounterLeft = 0;
runCounterRight = 0;
}


if((runCounterRight > 1||runCounterLeft > 1)&&runToggleSwitch == false) // if the counter is not reset and if it reached 2, we initiate the run function (which will be triggered by the bool running = true)
{

if(SDL_GetTicks() - runStart > 500) //i'm not sure anymore but now that I see it it looks like the same as above :/ not sure if this block is necessary
{
running = false;
runToggleSwitch = true;
}
else running = true;
runToggleSwitch = true;
runCounterRight = 0;
runCounterLeft = 0;
}
}[/source]

first and simpler : do anyone have a more versatile alternative for this to my system?

second: how can I adapt this to the SDL joystick?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!