How do I spawn a list of sprites randomly?

0 favourites
  • 3 posts
From the Asset Store
Build Social Apps, Chats and Advanced Lists using Firebase Realtime-Database
  • Hello, I am new to construct and I could use some help.

    I have a list of sprites that I want to create in game, and each needs to be created only once. The catch is that I would like for them to be spawned randomly, and I need one of the sprites (randomly chosen) to be spawned at a different spot. What would be the best way to implement this?

    My plan was to add the sprites to an array and select a random index to be spawned, creating the other 23 afterwards. However, it does not seem that I can add sprites to an array, as it only allows me to enter info about the sprites.

    Thanks for the help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I believe the simplest way is to add them to a family and then

    create object- family1

    that worked in construct 2

  • You need to decide if all these sprites will be separate objects, or if it can be a single sprite object with multiple animations/frames.

    If you need to spawn many different objects without duplicates, you can name them like Obj1,Obj2,Obj3... and use "System Create by name" action:

    Repeat 20 times
     : Create by name "Obj"&loopindex at (random(1920), random(1080))
    

    If this will be a single sprite - create this sprite, and then set a frame.

    Repeat 20 times
     : Create Sprite at (random(1920), random(1080))
     : Set Spirte animation frame to loopindex
    

    Instead of random position you can use invisible "spawner" sprites - then when creating a new object, pick a random unoccupied spawner.

    jjc001 Creating a family instance will pick a random family member, but this method may produce duplicates. And OP said he needs each sprite to be created only once.

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