Help with spawning objects from timers / families

Get help using Construct 2

Post » Wed Jan 29, 2014 12:24 am

I have the following setup:

playerUnits (family)
--> family instance variables: fireRate, bulletMatch
--> family behavior: Timer (by Rex)

playerBullets (family)
--> family instance variables: bulletMatch
--> family behavior: bullet



In the image above:

At SOL, each instance of the playerUnits family receives a regular (ie continuous) timer based on the various fireRate values I've assigned from my Dictionary object. Debugger shows all timers are working correctly.

What a timer triggers, and I'm assuming it picks the instance it triggers on, I am passing the instance's bulletMatch number to my "spawn pBullet" function.

I am then trying to pick the specific corresponding bullet object to be spawned based on matching playerUnits.bulletMatch with playerBullets.bulletMatch.

Current result: random bullet family objects being spawned, all simultaneously from all player family objects, and they quit spawning after 3 or 4 shots.
B
7
S
3
G
3
Posts: 22
Reputation: 2,385

Post » Wed Jan 29, 2014 12:58 pm

I ended up just dumping all of my bullet sprites into frames of an individual bullet sprite and setting frame on creation to match the player unit spawning it.

I would like to see a spawn family object by index, if it isn't already possible.
B
7
S
3
G
3
Posts: 22
Reputation: 2,385

Post » Wed Jan 29, 2014 1:52 pm

I would just give the player an instance variable with the sort of bullet they are firing and spawn the corresponding bullet.

When objects are in a family you can still adress them as isf they weren't.

So
for each PlayerUnits - call spawnbullet with parameter playerunits.BulletMatch
if param = 1 - spawn bullet
if param = 2 - spawn bigbullet

Doesn't matter that they are in a family.

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 31, 2014 2:46 pm

@LittleStain

I like your solution so much better and it simplifies so many things for me. Kind of like a switch statement.

I think I was trying to accomplish all of the "if param..." statements in one line which obviously didn't work at all, and is really not necessary when using functions that already save so much time and space on their own. I was mapping out all of the messy "if animation frame..." I was going to have to use before I read this.

I'm definitely going to remember this for the future. Thanks!
B
7
S
3
G
3
Posts: 22
Reputation: 2,385


Return to How do I....?

Who is online

Users browsing this forum: AllanR, brunopalermo, ST314, TheRealDannyyy, tunepunk and 23 guests