How do I stop duplicate sprites from appearing in my game?

Get help using Construct 2

Post » Fri Nov 21, 2014 11:31 am

Hi Guys,

I've posted before about this problem but having some trouble with a whack a mole game i'm creating using sprites which pop up into windows.

The way i've created it is shown below in the construct 2 code.

I understand using arrays is going to be the way to do this but i am struggling to get my head around how to use them in this way.

I will outline exactly what i am trying to achieve.

-I want 16 different sprites
-The 16 sprites pop up into 9 different windows
-I want the sprites to appear every 0.7 seconds with a MAXIMUM of 3 sprites at once
-I do not want the same sprite to duplicate itself (for example if the sprite is already up i do not want the same sprite twice)
-The sprites which appear every 0.7 is randomly selected from the 16 sprites.
- I want the sprites to pop up into the window and not just appear


I have attached the CAPX file which i hope with give some clarity on what i am doing.

Thanks so much guys, i've received some brilliant help so far here.

Image
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 17
Reputation: 234

Post » Fri Nov 21, 2014 2:13 pm

You don't want the same sprite duplicated or the same sprite playing the same the frame? In the latter case maybe you can check if the sprite is on screen AND if a particular frame is playing.
B
10
S
1
Posts: 54
Reputation: 958

Post » Fri Nov 21, 2014 3:14 pm

Hey Niko, the issue not having the same frame appear at the same time. What you suggested makes sense, but doesnt see, to work because when the call is made for an instance to move up, it doesn't always happen 1 at a time. So if 3 get called to move up and I tell it to display frame 3, all 3 instances come up as frame 3.

I need a way to talk only to one of the instances at a time. Really not sure if that makes sense. If you have a look at the capx file it should make sense.
B
4
Posts: 17
Reputation: 234

Post » Sat Nov 22, 2014 11:07 pm

Bump
B
4
Posts: 17
Reputation: 234

Post » Sun Nov 23, 2014 2:32 am

Here is the randomization fixed.
You'll need the RandomArray plugin.
Briefly, set the Random array size to the number of frames. I've set it to 10, as two of your last frames a duplicates, and it's clearer to see there are no duplicate frames when there aren't any to begin with.
On your timer event, rescramble the array, and copy this to a normal Array. Cycle through every active monster to find it's frame number in the Array and remove it. You then have an Array of frame numbers that are unique to this cycle.
In the selection event, set the frame to the first one in the array and then delete that same entry so that the Array is again unique for the next monster in this cycle.

The other change was to add an Active flag, to know which sprites are active and should be checked for duplicates, ignoring all others.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Mon Nov 24, 2014 10:51 am

@blackhornet, Thank you sooooo much. That is perfect. You are the man. Still getting my head around what you've done, but it works perfectly. I can't thank you enough.
B
4
Posts: 17
Reputation: 234


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 11 guests