[Solved] Bullet Limit (Number of Bullets on Screen)

0 favourites
  • 6 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • I want to have 4 Bullets (Projectiles) max on screen at one time. The Bullets destroy when it collides with any other object.

    What is the best way to set a Bullet Limit?

    My game is a Platform/Run 'n Gun.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Use a variable bulletTOTAL to track the number of bullets

    Each time you create/spawn a bullet add 1 to bulletTOTAL

    Each time you destroy a bullet minus 1 from bulletTOTAL

    Then use...

    Event -> Compare variable bulletTOTAL < 4

    Actions -> Create Bullet etc

  • The fun thing about Construct is that it keeps a count of the objects. First, make sure bullets are destroyed when out of layout.

    Then keep track, of many objects are on the screen. I typically assign some kind of global variable. NumberOfBulletsOnScreen = 0

    Now, when you press the space key (or fire key) count the number of objects on the screen. Number of bullets = bullets.Count

    '.Count' is appended after the object name to get the total number of that objects on the screen.

    For your conditions down "when space key is pressed (or whatever key is the fire key) AND NumberOfBulletsOnScreen < 0

    and the actions would be

    spawn new bullet

    NumberofBulletsOnScreen = bullets.count

    This will work because you will keep a constant track of the bullets on the screen every time you fire. The layout always starts it as 0 so it will always allow you to start firing. As you fire it will raise the number of bullets on the screen. When there are 4, it won't let you fire any more. But you need to make sure to keep track of the number of bullets on the screen when the bullets are destroyed too. So you need one more condition and action.

    Condition:

    Bullet-On Destroyed

    Action:

    NumberOfBulletsOnScreen = bullet.Count

    That will lower the variable and reset it as bullets are destroyed.

  • arontwose beat me to it with a simpler solution.

  • Even simpler,

    Add this to the shooting event:

    bullet.count < 4 (this is a "Compare two values" system event)

  • Thanks everyone!

    I ended up using what "7Soul" suggested.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)