I’m making a side-scrolling platformer game. I’ve made it so that the character runs, jumps, and shoots fireballs. However, I need to set up a way to prevent the player from holding down the fire button and letting out a steady stream of fireballs. I know that I could do this using setInterval, but (despite reading tutorials) I can’t figure out exactly how it works/how to implement it. Here’s the piece of my script where I want the firing code to go:
var number:Number = 1;
hero.onEnterFrame = function() {
if (Key.isDown(Key.SPACE)) {
fireball();
}
};
fireball = function () {
attachMovie("fireball", "fireball"+number, number);
_root["fireball"+number]._x = hero._x+10;
_root["fireball"+number]._y = hero._y-25;
_root["fireball"+number]._xscale = hero._xscale;
number += 1;
if (number == 50) {
number = 1;
}
};
Obviously, I cut out the rest of the code for the hero’s running, jumping, etc. because it’s not necessary. If you need to see it though, just post. Thanks for any and all help, it’s much appreciated!