How do I distribute sprites

Get help using Construct 2

Post » Mon Jul 21, 2014 2:30 pm

Hi

I'm using the script below to distribute sprites with random frames. The problem is that the frame "0" always repeats a few times. Any help? Thanks

Code: Select all
Function > On "distrSprites"
> System > For each local
>> System > Pick local where local.occupied = 0
>>System > Pick random local instance >> local > Spawn Sprite on layer 0
                                                                      >> Sprite > Set animation frame to Array (randomFrame)
                                                                      >> Array > Delete index randomFrame from X axis
                                                                      >> local >  Set occupied to 1
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Mon Jul 21, 2014 4:21 pm

It seems to me the picking is at fault. What does your Array look like?

Is

Code: Select all
>> System > Pick local where local.occupied = 0
>>System > Pick random local instance >>


in the same block or sub block? If it's in a sub event, try putting them together.
B
25
S
6
G
3
Posts: 197
Reputation: 3,355

Post » Mon Jul 21, 2014 4:34 pm

Hi @TwinTails

Both lines are in the same block/sub-event.

My array have the same number of sprite frames (16 values = 0 to 15)
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Mon Jul 21, 2014 5:08 pm

@TwinTails @RenatoB : when you use "for each", you already pick each instance one by one, in a row. You don't have to filter more.

>> for each (local)
>>>> if local.occupied = 0
>>>>>> spawn a random sprite
>>>>>> set local.occupied = 1

I know isn't your current problem, but it's important to point out. Then, the logic of the code you provided looks correct otherwise. We need to know more about your code to solve this bug !

Cheers,
Nathan
B
77
S
22
G
4
Posts: 311
Reputation: 12,704

Post » Mon Jul 21, 2014 5:24 pm

@Valerien: Thanks for the tip. I think that I need to maintain the "pick random local" line because the sprite is the same and the system choose a different frame using the array.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Mon Jul 21, 2014 7:40 pm

@RenatoB : if you have for example 16 instances of the object "local", the for each loop will go through each "local" instance one by one. If you sub-pick an instance, it will keep the one that's already filtered within the loop.
B
77
S
22
G
4
Posts: 311
Reputation: 12,704


Return to How do I....?

Who is online

Users browsing this forum: Bootfit, grigrizljac, korbaach and 15 guests