Hello everyone!

It has been quite sometime since I was on Daniweb, and a lot has changed.
Anyway, I have decided to "fix" my old Java school ISU and make it better. (I am not in school so don't worry, I'm not cheating.) Here is my problem: I want a bullet to fire when I press the space bar. Ok, I did that and it works. What I want now is when I release the space bar I want the bullet to stop but I need it to stop say after the bullet has traveled 5000 X coordinates. As soon as I release the space bar the bullet stops.

How can I "delay" the bullet being stopped?

Recommended Answers

All 5 Replies

you could try a while loop that takes in a character from the user.

while((scan.next()).equals(" "))

i dont know if the .equals() would work, but you get the idea?

Unfortunatly I don't understand. (As my username suggests) I am not that good at programming. But, I will try to implement a while loop into it, I think we are on the right track though.

Thank you for your help, I'll post more later.

that's the thing, I am using a keylistener. I want to know how to make the bullet travel for a bit then turn the value "blltFire = false". When blltFire = false, the bullet will stop animating and dissapear like I want, but it only travels as long as I hold the space bar down. I want it to shoot and move across the screen without holding down the space bar.

T-Dogg3030: I tied a while loop but it didn't really work out for me.

Thanks for the help so far,

If a snippit of code will help, tell me what you need and I'll post some of the code for you. (I'm just not sure what to upload right now)

Ok, I got the code to work by itself! I made a nested if statment that when I press the space bar, the bullet fires and after the bullet's X coordinate reaches 850, bulltFire becomes false stopping the bullet.

After thinking about while loops and how keylisteners work I remembered that the bullet is triggered by a boolean which is set to "true" when the space bar is pressed. All I had to do is make it false after it moved via my new nested if statment.

I want to thank T-Dogg3030 and RockJake28 for their help on this. (I feel quite embarressed that I figured it out my self after asking for help.)

Thank-you though for your time,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.