Stop Users Repeatedly Pressing a Key

0 favourites
  • 9 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • Hello!

    I am making a small game in Construct 2 and I am unsure how to stop users from repeatedly spamming the mouse button. I want there to be a two-second delay until the user can press the key again.

    How would I do this?

    Thank you,

    Orange

  • There are lots of ways of doing this...

    Here's one

    you can give your object an instance variable lets say cooloff

    then add "cooloff <= 0" to your fire trigger meaning cooloff must be 0 or less to work

    then when you shoot add a value depending how long you want to cooloff

    on mouse clicked      fire bullet

                          set cooloff to 20    (adjust this number to suit)

    then the condition...

    cooloff > 0     subtract 1.0*dt from cooloff

    sorry bit rushed, hope that helps...

  • There are lots of ways of doing this...

    Here's one

    you can give your object an instance variable lets say cooloff

    then add "cooloff <= 0" to your fire trigger meaning cooloff must be 0 or less to work

    then when you shoot add a value depending how long you want to cooloff

    >on mouse clicked      fire bullet

                          set cooloff to 20    (adjust this number to suit)

    then the condition...

    >cooloff > 0     subtract 1.0*dt from cooloff

    sorry bit rushed, hope that helps...

    Hey Pixel!

    Thanks for your reply, but I'm a tad confused.... would you have cooloff reduce every tick?

    Thank you,

    Orange

  • You don't need to add every tick, it will only reduce cooloff when it is above zero

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Dt is delta time the internal clock running all the time, just make one condition...

    (your object) compare variable, cooloff > 0....followed by this event

    (your object)subtract 1.0* dt from cooloff

  • Aah, I've figured it out for myself now. Thank you!

  • pixel perfick

    hope you don't mind me using that in the near future :P Very useful.. I find it funny how I can't think of something like that originally but as soon as someone says it I'm like: Oh yeah I probably did know that! <img src="smileys/smiley36.gif" border="0" align="middle" /> <img src="smileys/smiley9.gif" border="0" align="middle" />

  • Sulli Free to use, just give me credit, lol..kidding.

  • pixel perfick muhahaha <img src="smileys/smiley14.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)