Reload time

ok, i made a game with a guy and a gun. you can fire your gun continuously without stopping. i’m just wondering(cause firing continuously is cheap), if anyone knows how to make it so that your gun has a reload time (i.e. 1 sec)?

Well theres probably a bunch of ways to do this. This is probably not the best way to do it but make a seperate sub animation under the character guy and label it reload. Then…

[AS]
//under main guy for reload script
if (Key.isDown(Key.RELOAD) && !reloading) {
reloading = true;
this.gotoAndStop(“reload”);
}

//then go into the reload label animation. say if you have 15 fps make a keyframe on frame 15 and then add something like:

_parent.reloading = false;
_parent.bullets = whateverthemaxamountis;
[/AS]

You could do something like that, it’s probably not the best way to go about doing it though.

umm thats not exactly what i want, i want it so that(say spacebar is to fire) if you hold space, your bullet(in this case mine is a laser) will fire once a second or so.

in that try something like this…
[AS]
onClipEvent (load) {
fire = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !fire) {
fire = true;
this.gotoAndStop(“firing”);
}
}

//Then like 15 frames out on a sub firing animation add something like…
_parent.fire = false;
[/AS]

Or you can use setInterval, and only allow a new laser to be fired once the interval has passed …

yes tommy, that’s what i wanted, just didn’t know what the command was