How do I spawn a random sprite out of a set of sprites?

Get help using Construct 2

Post » Tue Sep 19, 2017 12:19 pm

Hi, I've recently been trying families in C2 and I found out you can't edit them during runtime which is bad considering what I'm trying to achieve.

Basically, I've 16 sprites (4 shapes, 4 colors) and I want to determine which ones to pick on spawn Family.
The 1st shape in its 4 colors is unlocked so the player can play the levels, the other 3 shapes will probably be an IAP.
The level itself determines which colors to spawn according to the colors of the exits.
So for example in level 1 I want Yellow and Blue to spawn so that becomes 8 sprites but if the player hadn't bought the rest of the shapes it'll only be 2 sprites.
Sorry if I make it look confusing if it's not already is.
B
27
S
10
G
2
Posts: 237
Reputation: 3,330

Post » Tue Sep 19, 2017 12:57 pm

You can create several families with different combinations of sprites and use them for spawning.
E.g.: SpritesFree, SpritesFreePlusPaid1, SpritesFreePlusPaid2, SpritesAll
Then when you need to spawn a new object, select one of the families depending on which one the player has bought.

Or since you only have 16 sprites, you can write a simple event like this:
Code: Select all
r=floor(random(16))
If r=0 Spawn sprite0
If r=1 Spawn sprite1
....
If r=7 & <player purchased this sprite type> Spawn sprite7
If r=8 & <player purchased this sprite type> Spawn sprite8
...
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Tue Sep 19, 2017 1:22 pm

@dop2000 but that'd still spawn different colors than the ones needed for the levels or it would not spawn anything in case of r={7,8,etc.}
This is what I've reached so far for color Blue (They're currently 3 shapes only)
Image

Would this even work? Should I continue for the rest of the colors or is there a better way of doing this?
B
27
S
10
G
2
Posts: 237
Reputation: 3,330

Post » Tue Sep 19, 2017 1:46 pm

Ok, here is the modified code:
Image
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,401
Reputation: 84,429

Post » Tue Sep 19, 2017 2:06 pm

@dop2000 Thanks, never used return values before but seems pretty less confusing than what I have.
B
27
S
10
G
2
Posts: 237
Reputation: 3,330


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 4 guests