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

0 favourites
  • 6 posts
From the Asset Store
More, less or equal
$15.30 USD
15% off
The game will give you a dog that appeared and you must say if he appeared more, less or equal.
  • 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.

  • 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.

  • 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.

  • Bump

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

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