How do I change the score based on the sprite clicked in a family?

0 favourites
  • 4 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • My game has random sprites appearing on the screen using a family. When the user clicks on a family instance, the instance is destroyed and the score increases by 1:

    This works great as long as their are just enemies in the family, Family_NY_2. However, in addition to randomly generating enemies, I would also like to randomly generate friendly units that should not be clicked, and if they are, the score should decrease. Is there a way to do this using families, or would you suggest an alternative method?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are friendly units also members of this family? You can define an instance variable "isFriendly" on it, and use it to distinguish friends and enemies in this event.

  • Looking over the tutorials for family instance variables, they show an example of a "health" variable, and decreasing the value by one when a bullet strikes a member of the family. In my case, I need to set the "IsFriendly" boolean value to "true" for friendly units and "false" with enemy units when a unit is created, then create a condition that checks the value of the "IsFriendly" value when a family sprite is clicked. Is this possible with a family instance variable?

    If not, I believe I can get around this by having conditions for the two friendly units, taking specific actions (like decreasing the player's score instead of increasing it) if a friendly unit is hit, and the normal action (increasing the score) if an enemy is hit.

  • This is doable with instance variable (family instance variables are just "regular" instance variables that are applied to all objects present in a family).

    You need to make sure to set the boolean "isFriendly" to true on spawning of your object, when it is a friendly unit.

    Then indeed, on click on a family object instance, check the value of its "isFriendly" instance variable.

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