alright i have a slight problem, im just testing some stuff, and everytime the space key is pressed i want one bullet to come out, however righty now you can just hold down space and it keeps firing…heres the code i used :
on (keyPress “<Space>”) {
i = i+1;
duplicateMovieClip(_root.bullet, “bullet”+i, i);
}
any suggestions on how to fix this?
try throwing a stop(); after the duplicateMovieClip just for ****s and giggles.
:p:
same result…or another way to do it would be to add a timer between shots?
instead of using duplicateMovieClip you coulse use attachMovie. the syntax is just like that, but…
on (keyPress “<Space>”) {
i = i+1;
_root.attachMovie(“bullet”, “bullet”+i, i);
}
in the library, right click on bullet and choose linkage, and make the reference name bullet, and choose export in 1st frame, and for actionscript (the default boxes taht are checked).
:p:
or you could do onRelease?
i don’t think that you can do onRelease for keyboard buttons…
:p:
really?
oh well
:lol:
:p:
to my knowledge you cant do on release for like the space bar
if (Key.isDown(Key.SPACE)) {
if (!_root.firing) {
i ++;
duplicateMovieClip(_root.bullet, "bullet"+i, i);
_root.firing = true;
}
} else {
_root.firing = false;
}
do that instead. this will only fire if ‘_root.firing’ is false. As soon as it fires, it sets this flag, and won’t fire again until _root.firing is set back to false, which will happen when the space bar is released.
I recently fixed this exact problem in my game.
also, i++ is short for i+=1 which is short for i=i+1
ah… there you go.
also, i++ is short for i+=1 which is short for i=i+1
i know, i just copied his code…
:p:
perfect, thanks you guys!