How do I generalise click event and its action using family?

0 favourites
  • 7 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Say I have several animal objects(cat, dog, goat etc....). On click of sprite i want to play respective sound of animals. Now to achieve this i have to detect click event on each sprite and perform corresponding action. Can I some how generalise this? May be using family. So If I click on any member of family, It should play respective sound stored in instance variable of the respective sprite. for e.g. All the sprite will have instance variable name 'sound' and they will store specific sound name in it. Like Dog will store 'dog_sound' and cat will store 'cat_sound'. So probably this way I have to write only one event - action pair.

    Animal -> Onclick() -> play Animal.sound

    Is it possible? Or any other way I can achieve the same?

  • Yeah sounds like you already know what you're doing, did you try it?

  • Just add the instance variable to the family, not to the instance.

  • I'm not clear how to do exacly...

    99Instances2Go If I add instance variable to family, how I will play different animal sound? bcas family instance variable can contain max one value. What I want is onclick of family I want to play respective sound of the member. If the clicked member is cat sprite it should play cat_sound, If the clicked member is dog it should play dog_sound and so on.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add all the animals to a family.

    Organise the names of the sounds so they are easy to use.

    Add a instance variable 'Scream' to family, type = text

    In the layout, click each animal, change the value for 'Scream' to the name of the audio file.

    In the events.

    Mouse > On object clicked (family)

    Audio > Is tag playing (inverted) .... tag = str(family.uid)

    ____________Audio > Play (by name) ... name=Family.Scream .. tag = str(family.uid)

  • thanks a lot 99Instances2Go, it worked. Where i was missing is that I was not aware of family instance variables accessibility to member sprites.

  • Oh, that had me puzzled a year ago too.

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