Randomize the Starting Frame of Animations

This forum is currently in read-only mode.
From the Asset Store
three fully animated characters ideal for your RPG side scroller projects
  • 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 <img src="smileys/smiley12.gif" border="0" align="middle" />

  • 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 :)

  • Of course!

    Thank you so much! It works perfectly now <img src="smileys/smiley1.gif" border="0" align="middle" />

  • 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.

  • 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.

    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.

  • No, random(22)+1 will return 1-22

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

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm sorry to say so, but you are wrong indeed <img src="smileys/smiley2.gif" border="0" align="middle" />

    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

  • 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?

  • Sorry silver,consider me suitably embarrased..

    Thanks tulamide!...looks like I learnt something too!...

  • 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 <img src="smileys/smiley1.gif" border="0" align="middle" />

    So thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)