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
362
S
216
G
75
Posts: 23,100
Reputation: 180,442

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
61
S
22
G
14
Posts: 1,480
Reputation: 16,373

Post » Thu Apr 25, 2013 12:52 pm

Oh - nice trick!
Scirra Founder
B
362
S
216
G
75
Posts: 23,100
Reputation: 180,442

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: anty21ro, Pulstar, randomly, rednka14, Yahoo [Bot] and 13 guests