Random generate object on layout

Get help using Construct 2

Post » Tue May 19, 2015 1:56 pm

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.
B
4
Posts: 2
Reputation: 211

Post » Tue May 19, 2015 3:47 pm

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 :D
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Wed May 20, 2015 12:19 am

Maybe this?
If you don't see the full image.
Press Cntl -
to zoom out.
Image
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.
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Thu May 21, 2015 4:33 pm

Thanks @aquadijoib.
I will try it.

@producermark11 I dont see all of img event zoom out.
B
4
Posts: 2
Reputation: 211



Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests