How do I spawn random objects from a set of objects

Get help using Construct 2

Post » Mon Apr 14, 2014 11:51 pm

I am making a falling game and I wanted to make it so as obstacles spawned, they could be one of 6-7 random obstacles. Is the only way to do this from a massive is statement, or can I do it programatically? The if statements are getting out of control since there are 15 permutations of the configuration, then wanting to add 4-6 options for each of 4 spots, its getting a little insane if I can do it programatically.
B
2
Posts: 3
Reputation: 156

Post » Mon Apr 14, 2014 11:54 pm

You could check out the simple flappy birds tutorial that is on the site. Yes I know its a sideways game but its still the same concept.

Move out of the way of randomly generated obstacles.
B
8
S
1
Posts: 76
Reputation: 949

Post » Tue Apr 15, 2014 12:04 am

Rather than a bunch of if statements spawning separate objects, incorporate all of your obstacles into a single object as different animations or frames with a corresponding number.

Example:
On spawn trigger:
> set localvariable to floor(random(x,y))
> spawn obstacle
> set obstacle animation to localvariable
B
7
S
3
G
3
Posts: 22
Reputation: 2,385

Post » Tue Apr 15, 2014 1:17 am

HJ1, I did it with both. Setting the animation worked, but the frame did not. If you set the frame and stop the animation, it will change every time a new object spawns, but setting the animation worked like a charm.
B
2
Posts: 3
Reputation: 156

Post » Tue Apr 15, 2014 3:47 am

Just a thought, but is it possible that when using frames you haven't set the animation speed to 0?

Happy that the animation method worked for you either way!
B
7
S
3
G
3
Posts: 22
Reputation: 2,385

Post » Tue Apr 15, 2014 9:13 am

If you get all your obstacles into a family, then you can just spawn the family. It wil choose a random object from the family. It's a bit less of a hassle than choosing a random animation, and each object can have it particular behaviour.
B
9
S
4
G
2
Posts: 12
Reputation: 2,772


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], brunopalermo, jorgmaquoi, kiki4construct and 24 guests