0penS0urce Posted October 31, 2015 Share Posted October 31, 2015 So, I have a game where the player repeatedly presses buttons in order from the screen. But, the user can cheat if they repeatedly press the buttons. So, How can I add a delay to a function, like a button press listener, so that it can't happen more than 2 times per second? Thanks For Your Help!!! Link to comment Share on other sites More sharing options...
chongdashu Posted October 31, 2015 Share Posted October 31, 2015 There are many ways to do it, and if you post what your code is like currently, we'll be able to give more direct advice. But you could simply do something with a timer, or a countdown:var lastClickTime = game.time.elapsed;// ... awesome code herebutton = game.add.button(0, 0, 'button', onClick, this);// ... more awesome code hereonClick : function(e) { var clickElapsedTime = game.time.elapsed - lastClickTime if (clickElapsedTime >= 1000) { // if at least one second has passed, perform action doSomethingAwesome(); lastClickTime = game.time.elapsed; } } jmp909 1 Link to comment Share on other sites More sharing options...
Recommended Posts