Animation frame is random(0,2), why is Frame 3 being shown

0 favourites
  • 13 posts
From the Asset Store
three fully animated characters ideal for your RPG side scroller projects
  • I have some flashing spots.

    There is an entry in my event sheet setting the animation state to 0 or 1 (green color and red colour). There is a third animation frame, which is yellow.

    The animation fram is set every x seconds with:

    floor(random(0,2))[/code:3lxhpdkz]
    
    However, when the page loads, several of the spots are in animation frame 3 (Yellow).  This is only when the page loads initially.   After a second or two, the fewer yellows are shown and the red and green take over.
    
    [attachment=1:3lxhpdkz][/attachment:3lxhpdkz]
    
    Here is my event sheet:
    
    [attachment=0:3lxhpdkz][/attachment:3lxhpdkz]
  • Have you set animation speed to zero?

  • (0,2) are 3 frames 0,1,2.

    (0,1) is correct.

  • (0,2) are 3 frames 0,1,2.

    (0,1) is correct.

    That's what I thought, but the manual says it doesn't include the upper number.

    random(a, b)

    Generate a random float between a and b, including a but not including b.

    So the manual must be wrong.

  • codah

    It is indeed. A and b are taken. And I think BanksySan is referring to the number 3, instead of questioning the number of algorithms that it's returning (0,1 and 2)

  • do you have more than 3 frames?.. if not, just use choose(0,1).

  • floor(random(0,2)) is perfectly fine. it will return only 0 or 1 and never 2. There must be an issue with something else.

    (0,2) are 3 frames 0,1,2.

    (0,1) is correct.

    Nope. random(0,1) will return value 0 to 0.9999..... but never 1 and floor(random(0,1)) will always return 0

  • yeah for random frames I always use: choose(1,2,3)

    but I think you can do round(random(0,2)) to give you values 0,1,2 but it ends up not being that random since 0.6-1.4 all become 1 etc.. whereas only values below 0.4 end up being 0.

  • correct expression of random between two values - n and m (where m > n):

    a = random(m - n + 1) + n

    you may need floor(random()) if you want integer values

  • The issue is likely that the speed of the animation is not set to 0 and as such it does display the last frame of the animation.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you set animation speed to zero?

    That would explain why it's getting yellow at the start, but never again.

    if the animation got the 3 then stopped, all subsequent changes would be permanent.

    That might also explain why some get there faster then others, if some are set to frame 2.

    A plan is beginning to form. I'll do some tests and post the results up.

  • (0,2) are 3 frames 0,1,2.

    (0,1) is correct.

    > (0,2) are 3 frames 0,1,2.

    > (0,1) is correct.

    >

    That's what I thought, but the manual says it doesn't include the upper number.

    random(a, b)

    Generate a random float between a and b, including a but not including b.

    So the manual must be wrong.

    do you have more than 3 frames?.. if not, just use choose(0,1).

    This behaviour of random is pretty common across platforms. It would be horrible if random(n,m) could return both n and m as the the space between n + 1 and m - 1 would be different.

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