Press any key or button

edited January 2019 in Help request

I was looking at implementing a "Press Any Key" or joystick button press function on a splash screen. I came up with this:


void SplashScreen::CheckForAnyKeyOrJoystickButton(){
    orxINPUT_TYPE inputType;
    orxENUM buttonID;
    orxFLOAT value;
    if (orxInput_GetActiveBinding(&inputType, &buttonID, &value)) {
        if (inputType == orxINPUT_TYPE_JOYSTICK_BUTTON || inputType == orxINPUT_TYPE_KEYBOARD_KEY) { 

            //close screen and move on.
            orxOBJECT *screen = this->GetOrxObject();
            orxObject_SetAlpha(screen, 0.0);
            
            this->SetLifeTime(0);
        }
    }
}


It actually works great. An interesting side effect is that after I close this screen and move on to the initialization of the main app, the key press remains. So if my game uses the space bar to start, by pressing the space in the splash screen, the following events occur:

1) Splash screen appears
2) User presses space
3) Splash screen closes
4) Title screen and events are set up (but only for a brief moment)
5) Game automatically starts without the user intending to, because the space key was carried over.

Comments

  • Ah that's an interesting and creative way to do it!

    If it weren't for the joystick support, a shorter way without side effects would be to simply call orxKeyboard_ReadKey until you get a get.

    Your approach is probably the shortest one to cover both keyboard and joystick though, here are a couple of ways I think you could get rid of the side effect. I haven't tested them though, so your mileage may vary:

    • Before the splashscreen, select an empty input set, when you want to process past the splash screen, select the input set you'd have used there
    • Retrieve the input's name, if valid call orxInput_ResetValue on it

    Lemme know if any of these work! :)

  • I ended up doing orxInput_ResetValue. Thanks for that. Oddly, the key press doesn't carry over anymore without or without the code. Perhaps something else was causing it.

    Perhaps its a timing issue.

    Either way, I'll keep the code in.

Sign In or Register to comment.