[SOLVED]How do I set events properly using families

0 favourites
  • 7 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • To clarify the title of the thread:

    I have a family called 'Enemies' which contains all of the sprites for monsters in the game. Each monster sprite has an instance variable called 'Onhit' that when changed to '1' causes an animation to happen among a few other things such as spawning a damage number sprite.

    I want to slim my code down (I made code for a bullet colliding with every single monster sprite which lead to a lot of events) and make it so when a bullet overlaps anything from the 'Enemies' family it changes the instance variable of the specific monster that was hit ('Onhit' to '1').

    If I do something like:

    'Bullet on collision with (family)Enemies'

    Any action that occurs as a result of that will affect every monster sprite that is within the 'Enemies' family.

    Thank you.

  • In your above example any action taken will only affect the one member of the family hit with the on collision.

    Look at changing the instance variable to the family rather than the individual sprites.

  • I apologize. I should have paid more attention to what I was writing.

    I have now created a family instance variable called 'FamilyOnhit' and changed it so that every monster has an event that triggers on 'FamilyOnhit' = 1 rather than using their own individual instance variable called 'Onhit'.

    When a bullet collides with the Enemies family it sets FamilyOnhit to 1 and affects every monster not just the one that was hit. How would I change the code to have it only trigger an event for the specific monster that was hit? How would I subtract from the 'hp' instance variable of a sprite called 'mushroom' (which is part of the Enemies family) using the an event regarding the bullet colliding with the Enemies family?

    If I code:

    Bullet on collision with (family)Enemies: Subtract 1 from mushroom.hp

    It will trigger that event when the bullet collides with any sprite that belongs to the Enemies family.

  • please post a link to the capx so we an have a look , or a screen grab of the events ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have the following example for when a specific monster is hit:

    I have separate events like those pictured above for each monster sprite in the game. Is there any way to do the above using Families in order to lessen the amount of code?

  • I'm going to make some assumptions so I apologise if I get this wrong.

    I don't think you quite grasped the power of families (that sounds a bit like a line out of a Disney film <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile">)

    Let's say you have several monsters which we will call mushroom crab, toadstool cat, fungus dog and mouldy fish. All of these monsters are added to a family which we will call family monsters.

    From your example above we could have

    If sword beam is overlapping family monsters


    family monster instant variable active equals 1


    sword beams instant variable critical is greater than 25


    set family monsters instance variable on hit to one

    So this would make no difference if a crab, cat, dog or fish are overlapped by the sword beam.


    And in your 2nd section basically everywhere where you are saying moon crab change that to family monsters.

    Here is a simple example of family use


  • You're right with your assumptions (I am a noob). I have been using Construct 2 on and off for a year and I have just discovered the use of Families. I also just finished changing all of the code over for the enemies to make use of the Family and it all works smoothly, Thanks!

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