Random Spawns

0 favourites
  • 11 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I would like to make it so that when a variable hits 0, a random amount of a sprite appear in random locations across the screen. How would I do this pls?

    -Thanks in advance ;)

  • + System: If variable = 0

    + System: Repeat int(random(yourNumber))+1 times

    -> System: Create object sprite on layer 0 at (random(maxXvalue), random(maxYvalue))

  • Also add a trigger once to that first condition to stop it continually firing.

  • So it would be:

    + System: If variable = 0

    + System: Trigger Once

    ++ System: Repeat int(random(yourNumber))+1 times

    -> System: Create object sprite on layer 0 at (random(maxXvalue), random(maxYvalue))

  • Thanks for the reply,

    so the conditional statements would be if variable = 0 and trigger once, then the actions would be what exactly?

  • + Condition: System: If variable = 0

    + Condition: System: Trigger Once

    ++ Sub-condition: System: Repeat int(random(yourNumber))+1 times

    -> Action: System: Create object sprite on layer 0 at (random(maxXvalue), random(maxYvalue))

  • + Condition: System: If variable = 0

    + Condition: System: Trigger Once

    ++ Sub-condition: System: Repeat int(random(yourNumber))+1 times

    -> Action: System: Create object sprite on layer 0 at (random(maxXvalue), random(maxYvalue))

    Will try later, thank u!!

  • No worries, here's an example to show it in practice:

    dropbox.com/s/fpgqh7g9w87hndy/randomSpawn.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No worries, here's an example to show it in practice:

    https://www.dropbox.com/s/fpgqh7g9w87hndy/randomSpawn.c3p?dl=0

    thank u so much! Could u explain this pls: int(random(maxSpriteNo))+1 ?

    thank u again!!

  • No problem :-)

    int(random(maxSpriteNo))+1 returns a random number of sprites to spawn and works as follows:

    -"maxSpriteNo" is the maximum number of sprites you want to spawn.

    -"random(maxSpriteNo)" generates a random float between 0 and maxSpriteNo, not including maxSpriteNo.

    -"int(random(maxSpriteNo)" removes any numbers after the decimal point of the randomly generated float, returning just the whole number - it's important to note that "int" doesn't round up, so 0.999999 will still return 0.

    -By this stage we will have whole number between 0 and maxSpriteNo-1, so we add 1 to provide a number between 1 and maxSpriteNo.

  • No problem :-)

    int(random(maxSpriteNo))+1 returns a random number of sprites to spawn and works as follows:

    -"maxSpriteNo" is the maximum number of sprites you want to spawn.

    -"random(maxSpriteNo)" generates a random float between 0 and maxSpriteNo, not including maxSpriteNo.

    -"int(random(maxSpriteNo)" removes any numbers after the decimal point of the randomly generated float, returning just the whole number - it's important to note that "int" doesn't round up, so 0.999999 will still return 0.

    -By this stage we will have whole number between 0 and maxSpriteNo-1, so we add 1 to provide a number between 1 and maxSpriteNo.

    Thank you so much for the detailed response, I understand it now! Thanks alot and have a great day! :)

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