Pick a sub-object of a family in an event?

Get help using Construct 2

Post » Thu Apr 25, 2013 11:54 am

I'm using families to create a generic enemy ship for a shoot-'em'up game, and the behaviours and such work well, however I'm run across a stumbling block.

I was wondering if there is a way to check what object has been picked from within a family, something like :

Event 1 - If 'Family1' Is a 'SmallShip' > Fire Small bullet

Event 2 - If 'Family1' Is a 'LargeShip' > Fire Large bullet



Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939

Post » Thu Apr 25, 2013 12:17 pm

The best workaround is just to add a family instance variable that says what kind of object it is or what kind of bullet it fires.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,564

Post » Thu Apr 25, 2013 12:45 pm

@Ashley

There's a nice little trick[code]+ Foreach Family1:
   + SmallShip pick by UID Family.UID
      -> Fire Small bullet
   + LargeShip pick by UID Family.UID
      -> Fire Large bullet[/code]

What I like to call C2's object type casting :D
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Apr 25, 2013 12:52 pm

Oh - nice trick!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,564

Post » Thu Apr 25, 2013 3:53 pm

Thanks @Yann!

This kills two birds with one stone - my next question was going to be about firing points - as another issue with referencing the family rather than the sub-family object, is that image points don't appear to be picked up when spawning stuff. (Same issue posted in another thread)

JohnnySix2013-04-25 15:54:25
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939


Return to How do I....?

Who is online

Users browsing this forum: ManuelPerez and 23 guests