How do I destroy 2 objects at the same time?

0 favourites
  • 14 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi,

    I'm currently creating an isometric game and I have some problems with creating and destroying the square map objects and the projection objects at the same time.

    At the moment I have only one enemy which has a solid map object for collision detection and the overall game logic. Also it has an isometric projection object which is only for the isometric graphics. When the game creates an enemy, an instance variable for the map object is set to a random number and the same one is set to the isometric objects instance variable. So when an enemy is destroyed (the map object) it will search for the iso object with the same random number and destroy that one aswell. This system works but has some problems when I try to destroy too many enemies at the same time. Sometimes the isometric object is still there when the map object is already destroyed. Also I had invisible enemies sometimes when the map object was still there although the isometric object was already gone.

    Maybe someone has an idea of what the cause for this problem could be? Or even a better way to do this whole thing?

    I already had a look at the containers, but I would like to have only one solid map object and one isometric enemy object with different animations, which will have parameters to adapt to different enemy types. This won't work with containers though I think. The goal is to have a dynamic system to easily add more and more different enemy types to the game.

    Any help is appreciated!

    Thanks!

  • I think containers.

    Besides that. Lets gamble. You must have a condition somewhere that picks several map objects, and you follow up by picking the iso objects that matches with only the first instance of map object in the picklist. A 'for each object" will solve that. Or a 'on collision' in stead of 'is overlapping'.

    Say you have several bullets somewhere in the air, or a dense pack enemy's.

    Now the condition 'bullet is overlapping enemy' will result in a picklist containing many bullets and many enemy's.

    map bullet is overlapping map enemy

    ____for each map bullet (sub event)

    ____pick iso bullet with the same instance variable as map bullet (same event)

    ..................................action ... destroy iso bullet

    ____for each map enemy (new sub event)

    ____pick iso enemy with the same instance variable as map enemy (same event)

    ..................................action ... destroy iso enemy

    ____an empty sub

    ..................................action ..destroy map bullet

    ..................................action ..destroy map enemy

  • have you try to create a function and pass different parameters?

  • You could try having an instance variable in both the map object and the iso object that stores each others uid. You can then get a direct reference to the paired objects from both directions.

  • First of all thank you all for your answers!

    I've now replaced every "Pick" Condition with a "For each" loop as 99Instances2Go suggested. After that there was a slight improvement in the invisible enemy count Now there was a bug where only some invisible enemies appeared sometimes with negative health values. I fixed it by moving the action for the destruction of the map objects directly after the Health <= 0 condition as it was placed after the id test condition before. So because there was no iso object to be found it didn't delete them. It seems like the game sometimes still fails to destroy the map objects but this at least destroys them in the next tick or so.

    I hope this will keep working as I add more content

    Thanks again!

  • I've now replaced every "Pick" Condition with a "For each" loop as 99Instances2Go suggested!

    I did ?

    No.

    I suggested to run trough all picked objects with a 'for each'.

  • Well..

    I tried using the "Pick object by comparison" and "For each" now and it seems to work the same as with the "compare variable" condition I just used for this.

    I guess there is multiple ways to do this

    Thanks again!

  • I did it like this:

    --(condition) For each "map_enemy" & map_enemy.health <= 0

    ---- (action): "map_enemy" destroy

    ____-- (subevent) For each "iso_enemy" & iso_enemy.id = map_enemy.id

    ____---- (action) "iso_enemy" destroy

    When I understand correctly you wanted me to put the "Pick by comparison" in the place of map_enemy.health <= 0 right? I think this is the same though.

  • General illustration of the problem that you created:

    https://www.dropbox.com/s/4eju1pbtlzrir ... .capx?dl=0

    Adjustment that i suggested:

    https://www.dropbox.com/s/5wl3o5nbpe3a8 ... .capx?dl=0

  • I did it like this:

    --(condition) For each "map_enemy" & map_enemy.health <= 0

    ---- (action): "map_enemy" destroy

    ____-- (subevent) For each "iso_enemy" & iso_enemy.id = map_enemy.id

    ____---- (action) "iso_enemy" destroy

    When I understand correctly you wanted me to put the "Pick by comparison" in the place of map_enemy.health <= 0 right? I think this is the same though.

    Nope.

    The problem happens on the moment that the enemy is losing health.

    As i said i gambled, you dont give that much info.

    I suppose it is with bullets, and you use 'on overlap'.

    Bullet is overlapping map_enemy

    For each map_enemy

    ...................... do your health thing

    I should have known that they do not directly get destroyed. Now, this is all it needs.

    But to be save (not sorry) you better keep the for each when destroying. After all it is possible that two enemy's go dead at the same time.

    Then the follow up is

    map_enemy.health <= 0

    For each "map_enemy"

    "iso_enemy" ... compare instance variabe ... iso_enemy.id = map_enemy.id

    ---- (action): "map_enemy" destroy

    --------------- "iso_enemy" destroy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Explination

    map_enemy.health <= 0 Pick ALL map_enemy with a health lower then zero

    For each "map_enemy" Since two can die at the same time. There can be more map_enemy picked. Got to run trough all picked map_enemy's. For each does that job one by one.

    "iso_enemy" ... compare instance variabe ... iso_enemy.id = map_enemy.id Lets now add the iso version to the picklist

    ---- (action): "map_enemy" destroy Actions work on the picked objects only. And we have now picked dead enemys 1 by 1 and their iso versions

    --------------- "iso_enemy" destroy

    Once you get the hang on picking. Live is easy. I promise. : )

  • Thanks for your detailed answers! 99Instances2Go

    I feel kind of dumb right now because I still can't get it to work properly. As you said, 1 bullet is destroying multiple enemies sometimes. I tried to create what you wrote in your last post:

    https://drive.google.com/open?id=0B7r2W ... U9UTi01TDQ

    This is what I had before (it destroys multiple enemies at once):

    https://drive.google.com/open?id=0B7r2W ... UxuQmdkRDQ

    What I tried to create from your explanation has some issues with invisible enemies.

    Here are some more screenshots of the events that could be a cause for this problem:

    This is for damaging the enemies with the bullets:

    https://drive.google.com/open?id=0B7r2W ... VpjbF95Z1k

    This destroys the bullet itself when it hits an enemy:

    https://drive.google.com/open?id=0B7r2W ... VpjbF95Z1k

    Maybe a capx of my project is a better way to find a solution <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> :

    Project CAPX

    It is a little messy <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green"> The Event Sheets where the problems are, are marked with "HERE". Also I left a comment on the exact events.

    Thanks for your patience! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • See if this makes sense to you.

    https://www.dropbox.com/s/msh0wzxsa3r7h ... .capx?dl=0

    Added a debug view (debug sheet), i needed to see whats happening.

    Fixed the map mouse. (map mouse sheet)

    Made a strict Die/Mirror/create routine (iso miror sheet)

  • 99Instances2Go,

    Thank you so much for the capx! I will have to look into it for a while to understand everything but I think it will help a lot.

    You even fixed some other issues I had with the collision box of the enemies, ...

    Thanks again!

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