Jump to content

  • Log In with Google      Sign In   
  • Create Account

I need help with joystick handling


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
2 replies to this topic

#1 tashaklikedi   Members   -  Reputation: 218

Like
0Likes
Like

Posted 26 September 2012 - 03:32 AM

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?

Sponsor:

#2 Pointer2APointer   Members   -  Reputation: 283

Like
0Likes
Like

Posted 28 September 2012 - 02:29 PM

Instead of explaining it all, Lazy Foo's tutorial should sum it up for you; well, at least somewhat:

http://lazyfoo.net/SDL_tutorials/lesson25/index.php
Yes, this is red text.

#3 tashaklikedi   Members   -  Reputation: 218

Like
0Likes
Like

Posted 28 September 2012 - 06:19 PM

I know that site and believe me I looked at it, but what I need is the key release moment for the hat.




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