Create random objects but not on the same positions

0 favourites
  • 5 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi!

    I am trying to create a chess memory game and want to create several pieces on the board at the same time.

    In order to create one piece on the board I have done as such: Event: System, every 4 seconds. Action: Create object on layer 0 X: choose (75,225,375,525,675,825,975,1125) Y: choose (75,225,375,525,675,825,975,1125).

    So each possibility for example X: 75 and Y: 375 represents a square. This works great my only problem is, if I want to create two pieces on the board at once, how do I prevent the two pieces from being created on the same square?

    Any help will be greatly appreciated.

  • Option 1: Create an array populated with all possible positions. Randomly select a value from the array then delete it from the array so it can't be chosen anymore. Repeat.

    Option 2: Place objects randomly. If it overlaps an existing object, delete it and try again. Repeat.

    Option 3: Use a Blackhornet's smart random number generator plugin that can prevents duplicates.

    There are other ways but I think these are the more common solutions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, option 2 didn't seem to work that smoothly last time I tried it. Option 1 is a bit complicated for me, I am not good with arrays, plus this has to be a continuous loop, I don't just want to create them once.

    Option 3 sounds interesting, I will check it out!

    Thank you for now! I will let you know if it works out!

  • With predefined positions you can put invisible sprites (SpawnPoint) in each position and do this:

    SpawnPoint Not Overlapping myObject

    ...System Pick random SpawnPoint -> SpawnPoint spawn myObject

  • Interesting! I will check this out!

    Thanks for reply!

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