How do i do probability to Spawn?

Get help using Construct 2

Post » Wed Apr 10, 2013 6:59 am

Hi Guys,

I am thinking about how to do a probability of spawning different sprites.

I have a set of 6 different sprites to spawn. Currently I am using int(random(5)) to get a random spawn of the sprites.

What I would like to do is to make the spawning of these sprites based on a probability?

Example:
Sprite 1 - 25%
Sprite 2 - 18%
Sprite 3 - 25%
Sprite 4 - 12%
Sprite 5 - 15%
Sprite 6 - 5%

And also I will like to be able to adjust the probability based on the events that happens during runtime.

A note also, is that currently my sprites are all stored within 1 sprite object with each sprite as a frame in the animation.

Hope to get advise from the community! Thanks
B
4
Posts: 5
Reputation: 735

Post » Wed Apr 10, 2013 7:25 am

int(random(0,101))

if less than 25 -> Sprite 1
if greater than 25 but less than or equal to 43 -> Sprite 2

etc.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Wed Apr 10, 2013 7:43 am

Thanks Excal,

I found this in the FAQs.. should have done it earlier.

http://www.scirra.com/forum/weighted-probabilities_topic48421_post304076.html

This would be more likely I would like to do. Thanks

Sorry for the post.
B
4
Posts: 5
Reputation: 735


Return to How do I....?

Who is online

Users browsing this forum: farfetchd83, Laurent, makkancs and 25 guests