Randomize the Starting Frame of Animations

For questions about using Classic.

Post » Tue Dec 04, 2012 10:08 am

Hello!

I have a foam animation for my waterfalls and I'm trying to find a way of randomizing its starting frame. I have a section where there are multiple waterfalls visible at once, so I'd like to avoid having all the foam looking synchronized.

I tried:

Start of Layout>

        For each Object: Foam      ------>     Set animation frame to random(22)+1
                                                                   Play Animation


It's a 23 frame animation. I hoped this would assign a random animation frame number to each foam sprite, and then play from that point. But they still all play identically. Any ideas?

Thanks for reading -Silver-2012-12-04 10:08:34
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Tue Dec 04, 2012 1:03 pm

I felt "Why?!" and tested it.
answer for it :

Play Animation ? Resume Animation

(
+ System: Start of layout
+ System: For each Sprite
-> Sprite: Set animation frame to random(4)+1 // ?5 frame animation
-> Sprite: Resume current animation
)

suppose "Play Animation" has funtion setting frame to 1st one.

sorry for broken english :)
B
45
S
9
G
7
Posts: 73
Reputation: 7,518

Post » Tue Dec 04, 2012 1:38 pm

Of course!

Thank you so much! It works perfectly now
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Sat Dec 08, 2012 2:29 pm

Errr..wouldn't random(22)+1 only give you 21 of your frames?

random starts at zero meaning random(22)+1 is numbers,1-21.

also adding random int to ensure you get random whole numbers may be an idea,as not sure if not,getting a whole number would stop a frame change?.....but it may.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Sat Dec 08, 2012 3:21 pm

[QUOTE=Pixel perfick] Errr..wouldn't random(22)+1 only give you 21 of your frames?

random starts at zero meaning random(22)+1 is numbers,1-21.

also adding random int to ensure you get random whole numbers may be an idea,as not sure if not,getting a whole number would stop a frame change?.....but it may.[/QUOTE]
No, random(22)+1 will return 1-22

-> random(22) returns 0-21, 1 added results in 1-22

Also, random returns the same type that you pass. (I already explained it in another thread). If you pass a whole number then the return value is also an integer, if you pass a float, the return value will also be a float.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Dec 08, 2012 3:40 pm

[QUOTE=tulamide]
No, random(22)+1 will return 1-22

-> random(22) returns 0-21, 1 added results in 1-22
[/QUOTE]
I thought random(22) returned 0-22? That's why I used random(22)+1, to give me a result of 1-23 instead of 0-22.

I may have to tweak the event to random(23)+1 if I'm wrong.-Silver-2012-12-08 15:43:39
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Sat Dec 08, 2012 6:51 pm

I'm sorry to say so, but you are wrong indeed

random(i) will return a number greater or equal 0 and lower than i

random(f) will return a number greater than 0 and lower than f

(i = int, f = float)

random(6) returns 0-5
random(6.0) returns 0.x-5.x
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Dec 08, 2012 9:21 pm

At least it's an easy fix! I thought random(22) meant Construct would go through every number up to 22, including 0. Hence adding the 1 to make it 1-23 instead of 0-22.

So for a 23 frame animation I need random(23)+1?
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Sat Dec 08, 2012 11:10 pm

Sorry silver,consider me suitably embarrased..

Thanks tulamide!...looks like I learnt something too!...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Sat Dec 08, 2012 11:13 pm

Hey, don't be sorry! You made me realize an error of my own! If you hadn't chimed in, I would never have known

So thank you!
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests