how to create random object ?!!

Get help using Construct 2

Post » Fri Jan 18, 2013 1:39 pm

Hi all !
How to create Random object in Construct 2 ?!!
B
21
S
6
G
5
Posts: 57
Reputation: 4,954

Post » Fri Jan 18, 2013 2:04 pm

Add the objects to a family, and then just System->Create Object->FamilyName.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Fri Jan 18, 2013 11:40 pm

hmm. How does that create a random object?
It sounds like it would just create 1 of everything. So all that does is just generate 1 object randomly.. that is strange. Good to know though.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Fri Jan 18, 2013 11:48 pm

Another thought would be to have a sprite strip of different objects and spawn an instance of the sprite to a random frame/Sprite in the strip each time...
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Sat Jan 19, 2013 2:10 am

I do it in a similar manner to what BluePhaze suggested, except that I use individual frames rather than a strip. Set the animation to be 0 fps and upon object creation a random frame is selected via: round(random(0,x)) where x is the number of frames/objects -1.

Here is a basic example I whipped up:

http://dl.dropbox.com/u/94794009/Contruct_examples/random_object_creation.capx

Another nifty command that can be used in a similar context is the choose command. Upon triggering one event you could randomly choose between the first three objects : choose(0,1,2) and upon another triggered event choose between the last 3: choose(3,4,5)zendorf2013-01-20 02:29:05
B
11
S
2
G
1
Posts: 108
Reputation: 1,899

Post » Sat Jan 19, 2013 11:19 am

When you select a family with 'create object' it picks a random object from that family.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Tue Apr 02, 2013 8:42 am

I have a question about your method thehen. So I setup my family and put the images inside. The object randomizes the images but it does them all and it keeps repeating instead of producing one and stopping.

After reading some tutorials I was seeing that I should set the family as an instanced variable along with the objects inside. My issue is I cannot get the random to stop and I was wondering if you had a little more info or anything to point me in the right direction on this.
B
7
Posts: 18
Reputation: 486

Post » Tue Feb 03, 2015 9:28 am

thehen wrote:When you select a family with 'create object' it picks a random object from that family.

can you post a example capx file please
B
6
Posts: 14
Reputation: 305

Post » Sun Mar 08, 2015 4:40 pm

Hi all
tried to repeat original posted file.
In my file random frames are chosen correctly, but when sprites start falling, all random instances are the same frame.

Does happen because I haven't used "family" ?
Also noticed that UIDs are different: original uid is 0, mine is 3
thanks
You do not have the required permissions to view the files attached to this post.
B
10
S
3
Posts: 25
Reputation: 709

Post » Mon Mar 09, 2015 10:56 am

hmm, found the solution.
Speed of animation should be set to zero
B
10
S
3
Posts: 25
Reputation: 709

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests