[MX] plz help!

Hi,

I have just read the tut on the shooting aspect of games and i tried it for myself. I altered it so that you shoot on the x axis and you shoot when the space button is pressed.

My question is, how do you make the bullets shoot when the space button is releases? And or can make the bullet shoot at an interval of one second or so when the space is pressed… The bullets for me are shooting at a continuous streem and that may be a too great advantage for a user…

Any help would be great, Thanks…

-n00bFlasher

Well now… Let’s see… You just do this and that and exit everything out and BAM it’s done…

Actually set up some sort of timer… And then every second… Allow the perosn to shoot or the such…

if(spacebar is pressed && timer is at 0)
{
SHOOT!;
}

Got it?

Or, create a function and use setInterval() to call it…

function shootBullet()
{
     // your shooting tween or animation goes here //
}

shootInterval = setInterval(shootBullet, 1000);
// this runs shootBullet() function in every 1 second...

Chech out the Flash manual or search the forum for more information on setInterval()/clearInterval() functions…

Thanks for the help guys :stuck_out_tongue: i’ll try it out… Thanks again!

  • n00bFlasher

Uhh, hi,

i tried your way first CyanBlue but it doesn’t really work. when the space bar is pressed, it takes one second before the bullets start shooting in a stream rather than shooting a bullet everysecond. Maybe I’m doing something wrong… where you said to place the tween or animation i put the AS where it tells the bullet to shoot…:q:

And playamarz, I don’t really understand how to set up a timer… If you can slowly walk me through it, that would be really helpful. Thanks again…(-:

Set up a couple of variables…

secTimer = # in seconds
framePerSec = The current fps your movie is set to
shotTimer = secTimer * framePerSec;

Then… Everytime a frame is loaded…

shotTimer–;

When shotTimer is to 0… Then it’s been that many seconds.

Yup… I know what that is… It takes that much of time to start one cycle with setInterval()… Don’t know why that is behaving like that… I just call the function one time and then do the setInterval afterwards…

shootBullet();
shootInterval = setInterval(shootBullet, 1000);

That does the job for me… :smiley: playamarz’s timer shouldn’t be that hard to implement too…