Families, targeting objects variable

Get help using Construct 2

Post » Thu Apr 19, 2012 12:40 pm

A Simple way to use families:
1. Add your sprites to the game (say all your "Enemy" sprites)
2. Create a Family called "Enemy Family"
3. Add all the enemy sprites to this Family
<Key Part below>

4. Add instance variables to your Family. Each variable will now become available to the individual members in the family

5. In C2, you need to have at least one instance on the layout (maybe outside the view) to be able to create them on runtime. Make sure you have at least one instance of each of the Enemies created on the layout

6. Edit the inherited instance variables of individual members in the Enemy Family. You will notice that each member retains the value set to its instance variable.

Eg: 'Health' is a Family variable. 'Health' for EnemyMemberA can be 100 and for EnemyMemberB can be 200.

Even when you spawn individual Family Members at runtime, they will get created with the initial set of individual values for the instance variable.

Hope this helps.
B
27
S
6
G
6
Posts: 20
Reputation: 6,132

Post » Thu Apr 19, 2012 12:47 pm

[QUOTE=Blam] I'm having the same problem as cs2curious.
If we just go by the family example that comes with cs2, how would we give each of the 7 different enemies their own health value? If all code is being told is that the laser has collided with "a member of the 'Enemies' family", I want to say "-100 from it's health" but have the starting healths all different. I'm thinking it should be something like "-100 to [family].member.'health'"?
So far I've just copied and pasted a heap of times but if I can find out how to do this it would save heaps of work.[/QUOTE]

Blam,
I haven't tried this, but I guess what would happen is that the correct value would get deducted from Health. You just need to have [Family].Health.
In the Event, when the 'Laser' strikes the 'Family', the individual member instance would get filtered from the entire set of [Family].[Members].instances.
Also, see the remark I added a while earlier on easy usage of Families.abhishan2012-04-19 12:49:43
B
27
S
6
G
6
Posts: 20
Reputation: 6,132

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests