How do I destroy sprites in a specific order?

0 favourites
  • 9 posts
From the Asset Store
Build your map with these isometric objects and terrains
  • To solve my problem, I tried:

    I tried calculating uid, but it is useless, because uid get recycled.

    I tried adding family instance variable when red gets hit but that family instance variable affects all green sprites, and it does not differentiate sprites.

    Description of a problem:

    I spawn 3 sprites in a line, their order in a line is random. There is green sprite (Green), red sprite (Red) and blue sprite (BLue) in rows that get spawned like so:

    ..............Red Green Blue (dots.... represent blank space)

    Green Red Blue

    ...................Green^ Red* Blue’’

    Blue Green Red

    A player will shoot at the sprites from the bottom. I have got this ready.

    Sprite green has instance variable = 1, sprite Red = 2, sprite blue = 3

    Then I generate random number 1, 2 or 3.

    Let’s say I get 2. Then I want a player to shoot any of the Red Sprites, because they have instance variable 2, it is possible, because they move.

    Let's say a player succeeds hitting sprite Red with an asterix Red*. I destroy the Red*, then I generate a number either 1 or 3.

    Let’s say I get 1. NOW I want a player to hit ONLY sprite red’s Green^ neighbour EXCLUSIVELY. THIS IS WHERE THE PROBLEM IS. I CAN'T do it, because I do not know how to pick this particular sprite. I want the player to keep shooting but only hitting Green^ takes effect. Once a player would do it, I destroy Green^.

    Then I want a player to shoot sprite marked with quotation marks Blue’’ EXCLUSIVELY just like the Green^ described above. I CAN'T do it.

    After that the whole logic starts from the beginning with a random number selected.

    I have got the shooting ready. I cannot do the destruction in the right order as described above.

  • Should be added to your player bullet / shooting events.

    You don't need instance variables because they're different objects.

    Have your global variable set to 1,2 or 3.

    In your shooting logic, something like :

    bullet on collision with green, if gv=1 destroy, else do nothing

    bullet on collision with red, if gv=2 destroy, else do nothing

    bullet on collision with blue, if gv=3 destroy, else do nothing

    I might not be understanding the game correctly through from the description, if so let's see a video or the game file.

  • Thanks for contributing, but it is not what I need. I basically want to destroy sprites in a row without destroing other sprites. I will allow bullet to pass other sprites from a different row till the chosen row is destroyed but according to a random order based on a unique random number. Like I showed.

    The first sprite to be destroyed can be in any row and it can be any sprite in the row. But The choice of the sprite to be destroyed first is based on a unique generated random number from 1 to 3. that is why i have instance variables to check them against the random number. Once a sprite is destroyed correctly, i want a player to destroy another sprite but this time in the very same row based on a different unique number i.e. no the one from the first shooting. Then the last sprite is to be destroyed in the same row.

    In other words, once a player hits one sprite correctly, because for instance he gets random number 1 and green sprite is the one with instance variable 1, I further want the player to stay committed to destoying other sprites in the same row. The player will have two other sprites to choose. However, he is not free to choose, because he is given a random number again, and he has to identify the sprite to destroy. At last he is left with the last sprite in the row to destroy.

    And the cycle repeats.

    Right now i have tried different things and my capx is a mess. Will try to do something about it if no one gets what i intend to do.

  • What's the problem then? It sounds like you know what you are doing and you have the random number allocated to 3 sprites in the row.

  • I'm not completely sure what you wanna accomplish but if it's anything close to what I'm thinking then maybe this will work. Do something like if green is on screen set red and blue collision disabled. That should let the bullets pass through them and only hit enemies that are red.

  • Thanks a lot, I have finally made it work. Now, I am stuck at having a better version of randomiser. I stumbled upon Fisher Yates, but I cannot reuse it. Have a look here with image and capx.

  • Well unfortunately Arrays isn't something I'm good at haha so I can't help with this part but I did make a tutorial a about spawning stuff randomly so I'm not sure if this will help but you can update it and have enemies spawn at certain locations on your layout or whatever. Other than that... at least you are not stuck on that other part anymore.

    Subscribe to Construct videos now
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the video. I had a glimpse of clarity and managed to get unstuck with the second one as well. I posted a screen shot with an answer.

  • Well I'm glad I was able to help with both issues! Good luck on your project!

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