How do I create random instances?

0 favourites
  • 3 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I want to create random instances but with some rules :

    1- instances should be the same copy of the original object (no change in size).

    2- instances have the same Y value (raw of instances).

    3- X value of each one should be the multiply of the instance width (for example 160 pixel).

    4- no 2 instances should be created overlapping each other.

    the result of that should be a raw of instances at certain positions arranged randomly like this for example

    (instance - space - space - instance - instance - instance - space - instance - space - space - space - instance) etc.

    each instance and each space should have the same width and aligned to each other.

    in the game I'm working on I'm creating columns passing the screen (scrolling) and destroyed when they become outside the layout as they left the right side of the screen, but i need them random.

    i tried using "choose" like this :

    if instances count < 2 ---------> create instance at : y=240, X= Choose (160,320,480,640)

    but it didn't work as i want, C2 may create 2 instances on each other.

    I'm not familiar with arrays and still trying to understand them, so for now what can i do to achieve this ?


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There's a couple of ways to go about it. Here's my take on it if I understand you correctly. There is no reason an instance should change size when it's created.

    Create a small sprite called SpawnBox and set it's property to invisible

    System> Every 2 seconds

    if instances count < 2 > System > Create Object > SpawnBox at : y=240, X= Choose (160,320,480,640)

    Create a dual condition with (X) being inverted

    SpawnBox > On Created > SpawnBox ...... > Spawn Instance

    instance > On Overlap (x) with Instance ... > SpawnBox Destroy

    Else > SpawnBox Destroy

  • Thanks for help, i don't know if you got the idea or not, and I'm sorry for my poor language

    the attached image shows what i mean : randomly arranged columns but at certain positions, the distance unit is the instance width or the multiply of it.

    so the generated columns may be : adjacent (space = 0) or away from each other by the instance width (160 pixel for example) or away from each other by 160*2, 160*3, 160*4 etc.

    the adjacent columns may be 2 of them or three or four.

    same thing for spaces, 2 adjacent spaces units may be or three or four.

    randomly but with some rules.

    hope i explained it correctly this time and many thanks for your reply.

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