How do I spawn 20 objects at random locations?

0 favourites
  • 5 posts
From the Asset Store
20 high-quality 2D monsters. This asset is perfect for a side scrolling game, or even a turn based RPG type game.
  • Hi,

    I'm working on a game where I want random collectibles to be spread out around the map in say 20 random locations. However, my current loop just doesn't stop spawning new objects. How can I do this right?

    Current loop:

    System Repeat 20X > System CreateObject Horde2 on layer 1 at (random(0,2000), (random(0,2000))

    System > Stop loop

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try putting it inside the "Trigger Once" Event under System...

  • for these kind of loops I often use a while, I add a var like maxdeploy or deploycount.

    spawned objects

    while

    (compare 2 vars) Object.Count <= maxdeplox

    deploy/spawn

    created objects (add another var, deploycount = 0)

    while

    deploycount <= maxdeploy

    action: add 1 to deploycount, create object

    this gives you a variable(s) to play with for how many you can deploy :)

  • You can put the repeat statement in a function, then just call the function when you want the spawn to happen (like on start of layout).

  • Thank you!

    I ended up putting the function within a larger one that I called once when the layout starts up. Thanks for all your help!

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