How to set random spawn choices

Get help using Construct 2

Post » Tue Feb 18, 2014 8:49 am

Hello,

I need some tips whats the easiest or most effective way to randomize my powerup spawns.

Case is like this:
i have one point from wich i spawn powerups and since i have several of them i would like to randomise choice.
Lets say every 3 seconds spawn powerup1 or powerup2 or powerup3 etc.

Thanks!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Feb 18, 2014 8:56 am

How are your power ups organised ? Are they all the same object, with different animation/frame ? If so, you just have to spawn one power up, set its animation to "floor(random(3))+1" (witch will sent back 1, 2 or 3, so add a prefix before it) and you are done.
If it's different object, you will want to make a function "spawnPowerUp" that will start by doing a random, storing it in a local variable, and then will instance an object depending on the random. Example in this link.
B
17
S
8
G
4
Posts: 461
Reputation: 6,137

Post » Tue Feb 18, 2014 9:00 am

instead of

floor(random(3))+1

you could also use

choose(1,2,3)

If you are using different objects use one of these two expressions to set a variable and create a differnt object based on the value of the variable.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Feb 18, 2014 9:03 am

@LittleStain Thanks ! Didn't know this one ! It will simplify a lot of things :) (btw, nice new avatar ^^) Thanks again !
B
17
S
8
G
4
Posts: 461
Reputation: 6,137

Post » Tue Feb 18, 2014 9:10 am

Thank you for your advices...

I could go either way but theres one matter later in game...
Later i intent to make collecting specific powerup as assigned.

example:

In upper left corner of UI shud be immage of certain powerup that is assigned and only that one when collected would give bonus and rest of powerups that spawn would not.

Having this on mind wich approach would be better?

Thanks!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Feb 18, 2014 9:15 am

Either, it won't change. The "problem" you described just now is during the powerUp collection, not spawning. Either way would be usable later on. But personally I would go with multiple objects in the same family. It seems the most easy to scale right now.
B
17
S
8
G
4
Posts: 461
Reputation: 6,137

Post » Tue Feb 18, 2014 9:27 am

Thank you, i will try that approach.

cheers!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Wed Jul 02, 2014 10:25 pm

Thank you very much, Guizmus! I was hoping to find a similar answer in this forum and was lucky enough to stumble upon your posts here. Good stuff!
B
9
S
1
Posts: 33
Reputation: 612

Post » Thu Jul 03, 2014 6:07 pm

Hey everyone! I'm kinda stuck with the situation when I need to have the sprite to appear in several specific locations randomly with different frequency ( up to the certain point with 3 sec interval then less).
Any ideas?

Thanks a lot.
B
4
S
1
Posts: 1
Reputation: 359


Return to How do I....?

Who is online

Users browsing this forum: Bro7hers, ketramtu18 and 7 guests