Random frame (uniqe)

Get help using Construct 2

Post » Thu Nov 14, 2013 2:33 pm

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
Flemmingflemmig2013-11-14 15:10:42
B
33
S
17
G
11
Posts: 350
Reputation: 8,697

Post » Thu Nov 14, 2013 3:09 pm

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.nimos1002013-11-14 15:13:57
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Nov 14, 2013 3:13 pm

Could you please help me out with a little more in how to ...
havent saved a variable before

thanks for reply :-)
B
33
S
17
G
11
Posts: 350
Reputation: 8,697

Post » Thu Nov 14, 2013 3:15 pm

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>nimos1002013-11-14 15:21:32
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Nov 14, 2013 5:31 pm

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.
http://s000.tinyupload.com/index.php?file_id=02408718448855364137

Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Thu Nov 14, 2013 9:34 pm

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





Thanks again
R/
flemming
B
33
S
17
G
11
Posts: 350
Reputation: 8,697

Post » Thu Nov 14, 2013 10:48 pm

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)mindfaQ2013-11-14 22:48:57
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, Yahoo [Bot] and 9 guests