How do I place multiple sprites randomly

0 favourites
  • 9 posts
From the Asset Store
Spooky Places game assets for 2D endless runner action adventure game.
  • Hi

    I have 10 sprites and I want to place them in the map randomly.

    How do I prevent one or more overlapping the one to the other?

    thanks for the reply

  • The only way I can see would be to create every sprite at random positions, then check if any sprite is overlapping another one, and if so change one of the sprites' position to another random position until no sprites are overlapping (see attached .capx example file).

  • Hi

    Thanks for the help. I I try it today.

    I also think of using an array and random number ...... I have to study us a little bit, I hope it works.

  • hi

    Kan your code works very well if the sprites are 10, if the sprites are 20-30 gives the problems of overlapping.

    I'm at a good point in creating a random map using arrays. As soon as the code is ready I put it in the forum.

  • Hi

    After several tests I have finished my mini random map generator. It seems to me that everything is working fine but I would like to get your opinion to try to improve the code, find bugs and add new features.

    In fact I would like to use the code to create a random survival game with randomly generate the map, items, enemies etc.

    opss ..... I can not enter urls (300 rep required).

    How can I do?

  • Here is my email address, I will send the urls for download by mail.

    napouno (at) libero ( dot) it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • u can try using set position x random(0,860)

    set position y random(0,480)

  • u can try using set position x random(0,860)

    set position y random(0,480)

    Hi

    But so is the sprites (if they are many) can overlap.

    To me, the array is a good solution.

  • you can make them not overlap, with a event checking the overlaping, and say this in condition

    if overlaping (same object type) set y x pos to object type overlaps bbox top or left or right + self.width or -self width that means when it will overlap same character type will move to the left or right edge of that character and has a space of his total width or height depends now where u want it to move up down left or right

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