Random generate object on layout

  • Hey,

    I searched forum but not found solution for this task.

    In my game I want to random generate n object that don't overlap each other.

    My solution is destroy object which overlap other generated object but then count of object don't match number n.

    Peter.

  • Hi,

    I can't upload a screenshot but that's how it works for me:

    Global Number "NumberOfObjects" = 40 <<<<<(change this to the max amount of Objects that should be spawned)

    [Group] ObjectSpawn:

    System: Every tick

    ----------> (SubEvent) If Sprite.Count < NumberOfObjects -------> System: Create object Sprite on layer 0 at random...

    ---------->(SubEvent) If Sprite is overlapping Sprite --------> Sprite: Destroy

    Just do this if you want to stop spawning the objects:

    Sprite: Is NOT overlapping Sprite ------> System: Set group "ObjectSpawn" deactivated

    System: Sprite is NOT < NumberOfObjects ------^

    I don't know why i can't upload images :/

    I hope it helps

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe this?

    If you don't see the full image.

    Press Cntl -

    to zoom out.

    This will keep all your objects and it will keep trying to reset the objects until none are overlapping.

    Of course your set positions will need to be appropriate for your game.

  • Thanks

    I will try it.

    I dont see all of img event zoom out.

  • pio3m you might find what you looking for in these demo

    https://www.dropbox.com/sh/eioscti86bpr ... 7YPza?dl=0

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