Continuously firing of bullet

please advice me on how to fire a bullet continuously !! using analog or actionListener
thanks in advance

Well @playlikeme_99 there are multiple ways to do this but for me i would make use of a controller.
When you start to fire enable the controller.

The controller will do something like attaching a bullet to the scene at a specific time interval.

Maybe a solution into Cross-Platform Vector Shooter: jMonkeyEngine - Envato Tuts+ Game Development Tutorials

1 Like


got it thanks i did it by on Analog method

Remember that games run at different speeds in different devices. If a game runs at 30 FPS, fires 30 bullets. If it runs at 60FPS, it fires 60. That’s unfair. If you simply fire a bullet everytime it detects input, you’re not controlling the rate of the firing bullets. So, let me give you an example:

  • Think of a fire rate. Suppose you only want to fire 10 bullets per second. 1 second / 10 bullets = 0.1 seconds between bullets.

  • Now, create a variable to store the firing rate. If you’re not going to change it later in game, you can set it as final.

    private final float FIRING_RATE = 0.1f;

  • Create a float variable that will work as a timer for the bullets. Add the tpf to it in your update() method.

    private float timerBullets = 0;
    public void simpleUpdate(float tpf) {
    timerBullets += tpf;

  • On your onAnalog() method, do the following:

    onAnalog(String name, float intensity, float tpf) {
    if(name.equals(MAPPING_FIRE) {
    if(timerBullets => FIRING_RATE) {
    timerBullets = 0;
    // your code to fire bullets

Here you go: a simple way of locking the fire rate in slow and fast computers.

thanks for the help bro!!!

1 Like

also how can we make a lag in between every fire of the bullet
for example a shotgun wil have to wait until its next bullet gets loaded!

Simply add a boolean to the weapon like isReloading for the amount of time you wish it to reload.

Then use the update loop to check if the time has expired, once it has remove it.

Then simply check isReloading to see if the weapon is ready to be fired again.