0 Favourites

Random frame (uniqe)

  • Hi

    I use the this for random frame in sprite

    set animation frame to round(random(20))

    How can I avoid getting the same frame twice

    eg I have 5 sprites on layout and want them to

    show a frame between 0-19

    but not the same frame more than once

    Update

    Found this tutorial but cant figure out to use it with

    a sprite .. it use a text object

    Random without duplicate

    Cheers

    Flemming

  • You can just save the last frame in a variable (Last_frame) and test against it after you make a random roll, and if they match make a new roll, else store that frame number in the "Last_frame" and change the frame.

  • Could you please help me out with a little more in how to ...

    havent saved a variable before

    thanks for reply :-)

  • You just make a Global variable and give it a name.

    Like: (You just right click an empty area in the event sheet and choose "Add global variable")

    Global Last_frame = -1

    Then in the event you just add: (System->set value -> choose the variable and set it to the value of the frame number that was chosen, in the random roll)

    Last_frame = <the frame nr>

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • The solution proposed may work if you only wanna spawn two sprites, but not with more than that.

    This would work with as many as you like.

    s000.tinyupload.com/index.php

    <img src="http://666kb.com/i/cj935bhtsbtsqknck.png" border="0" />

  • SUPER ... Thanks !!!!

    Got it running ... very helpful

    After the object is created with random frame I try to spawn

    a sprite slice..

    It almost work... but its not every time

    sometime it only spawns on 4

    maybe there is a better way :-)

    <img src="https://dl.dropboxusercontent.com/u/22406377/C2_random.jpg" border="0" />

    Thanks again

    R/

    flemming

  • If you have 20 frames ranging from 0 to 19, you need to scale it properly. (set size to 20,1,1 and use random(20-loopindex))

    You don't need the helper2, it is not used (was just a leftover)

    I am not really sure what you want to achieve with the spawning. Do you have all possible sprites covered? Or maybe you have some overlap? (you could test that by setting the opacity of the slice to 50, as you could notice when 2 congruent pieces are on top of each other)

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