How do I place multiple sprites randomly

Get help using Construct 2

Post » Wed Feb 25, 2015 7:09 pm

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
B
10
S
3
Posts: 43
Reputation: 817

Post » Thu Feb 26, 2015 11:09 pm

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).
You do not have the required permissions to view the files attached to this post.
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Fri Feb 27, 2015 11:49 am

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.
B
10
S
3
Posts: 43
Reputation: 817

Post » Sat Feb 28, 2015 6:21 pm

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.
B
10
S
3
Posts: 43
Reputation: 817

Post » Sun Mar 01, 2015 11:53 am

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. :idea:
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?
B
10
S
3
Posts: 43
Reputation: 817

Post » Sun Mar 01, 2015 12:39 pm

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

napouno (at) libero ( dot) it
B
10
S
3
Posts: 43
Reputation: 817

Post » Sun Mar 01, 2015 8:37 pm

u can try using set position x random(0,860)
set position y random(0,480)
ImageImage
B
56
S
15
G
64
Posts: 1,259
Reputation: 39,696

Post » Mon Mar 02, 2015 4:52 pm

gamecorpstudio wrote: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.
B
10
S
3
Posts: 43
Reputation: 817

Post » Tue Mar 03, 2015 12:45 am

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
ImageImage
B
56
S
15
G
64
Posts: 1,259
Reputation: 39,696


Return to How do I....?

Who is online

Users browsing this forum: RBuster, Yahoo [Bot] and 2 guests