How do I spawn 20 objects at random locations?

Get help using Construct 2

Post » Fri Nov 08, 2013 1:27 am

Hi,

I'm working on a game where I want random collectibles to be spread out around the map in say 20 random locations. However, my current loop just doesn't stop spawning new objects. How can I do this right?

Current loop:

System Repeat 20X > System CreateObject Horde2 on layer 1 at (random(0,2000), (random(0,2000))
System > Stop loop

Thanks!
B
2
Posts: 6
Reputation: 187

Post » Fri Nov 08, 2013 1:48 am

Try putting it inside the "Trigger Once" Event under System...

B
8
S
3
G
1
Posts: 34
Reputation: 1,395

Post » Fri Nov 08, 2013 1:48 am

for these kind of loops I often use a while, I add a var like maxdeploy or deploycount.

spawned objects

while
(compare 2 vars) Object.Count <= maxdeplox
deploy/spawn


created objects (add another var, deploycount = 0)
while
deploycount <= maxdeploy
action: add 1 to deploycount, create object


this gives you a variable(s) to play with for how many you can deploy :)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Fri Nov 08, 2013 2:17 am

You can put the repeat statement in a function, then just call the function when you want the spawn to happen (like on start of layout).
B
100
S
32
G
11
Posts: 1,552
Reputation: 21,622

Post » Fri Nov 08, 2013 5:27 am

Thank you!

I ended up putting the function within a larger one that I called once when the layout starts up. Thanks for all your help!
B
2
Posts: 6
Reputation: 187


Return to How do I....?

Who is online

Users browsing this forum: Sparkz and 3 guests