Load random animation frame

Get help using Construct 2

Post » Tue Nov 27, 2012 5:46 pm

Hi, I'm a C2 newbie... I have a project that requires a button to be clicked, that when clicked will look through the entries in an array, all of which are set to either 0 or 1 (i.e. inactive/active) and randomly pick one of the entries that is active.

Then, take the array position of that entry and use that to set a frame on a sprite.

For instance, if there's an array with a width of 5, (0,1,2,3,4) and they are set to values of (0,1,0,0,1)... it should select at random either array entry 1 or 4, and then set the image frame to frame 1 or 4.

How can I do this? I've tried a bunch of times in various ways but it never works right for me.
B
10
S
4
Posts: 13
Reputation: 1,151

Post » Fri Nov 30, 2012 7:07 am

One option would be to duplicate your initial array, and randomly pick an index up to the width. Grab that value and use Array.Delete(x) to remove that entry. Decrement your width value, and then do it all again. You'll eventually end up with nothing left.
ImageImageImage
B
67
S
19
G
124
Posts: 3,215
Reputation: 74,417

Post » Sat Dec 01, 2012 5:12 am

Psssst!

http://www.scirra.com/tutorials/252/random-animation
Zelda Gamekit (my project)

Example capxs I have made:
Zelda-Style Inventory
Zelda Hearts System

The unwritten "How do I" capx etiquette! Nearly always provide a capx of the problem you have, and try to isolate the problem and/or no capx above 10 MB. :)
B
38
S
19
G
26
Posts: 438
Reputation: 16,581


Return to How do I....?

Who is online

Users browsing this forum: GSquadron and 24 guests