pressing a button triggers many func runs

hi,


Just testing out a gamecontroller in my game. (Swift) iOS.


buttons work using the code i found in a tutorial - but when i press a button in the game, the func associated with that button, for example, fire or jump, runs dozens of times in the microsecond i press the physical button!


how can i cater for that and allow only one press at a time ??


thanks

Replies

A simple Bool variable would stop that. Something like...


if (alreadyPressed == false) {

alreadyPressed = true

//shoot

}


Then of course test to see when that same button isn't being pressed and that will tell you that user lifted off the button, and you can set alreadyPressed to false again.