PDA

View Full Version : Stopping keyboard button "rapidfire".


GLHeX
12-11-2002, 08:23 PM
Hello hello,

well I have a little bit of a problem.

I'm making a little game and when the user presses the space bar, a ball shoots from a cannon up through the stage.

Now when I tap the space bar a single ball shoots from the cannon and into the air. But when you hold the space bar down it shoots a lot of bubbles at once. And since they arent unloading untill they are out the the stage, the movie gets alittle sliggish.

Is there a way to put a delay of sorts on the spacebar so that every half a second or so the user would be able to shoot a ball?

I noticed the mouse wont do this, but due to the nature of the keyboard, holding down "y' for a scond produces: "yyyyyyyyyyyyyyyyyyyyy".

I need to stop that. Any ideas?

Thanks a lot.

Abelius
12-11-2002, 09:43 PM
I guess you could mask the whole thing into two functions, where one function shoots the fireball every set amount of miliseconds (use setInterval()), and the other function stops shooting the fireballs, or whatever :)

The function that starts shooting should be triggered by the mouseDown, since that's the one thing that happens ONCE... :)