View Full Version : firing one bullet per press
frookan
July 27th, 2004, 04:42 PM
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?
bodyvisual
July 27th, 2004, 04:43 PM
try throwing a stop(); after the duplicateMovieClip just for ****s and giggles.
:p:
frookan
July 27th, 2004, 04:52 PM
same result...or another way to do it would be to add a timer between shots?
bodyvisual
July 27th, 2004, 04:55 PM
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:
Jeff Wheeler
July 27th, 2004, 04:58 PM
or you could do onRelease?
bodyvisual
July 27th, 2004, 05:00 PM
i don't think that you can do onRelease for keyboard buttons...
:p:
Jeff Wheeler
July 27th, 2004, 05:01 PM
really?
oh well :P
bodyvisual
July 27th, 2004, 05:01 PM
:lol:
:p:
frookan
July 27th, 2004, 05:03 PM
to my knowledge you cant do on release for like the space bar
dal platinum
July 27th, 2004, 05:14 PM
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 ;)
bodyvisual
July 27th, 2004, 05:17 PM
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:
frookan
July 27th, 2004, 05:32 PM
perfect, thanks you guys!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.