Help with spawning objects from timers / families

0 favourites
  • 4 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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

    <img src="http://i.imgur.com/o91PyE1.png" border="0" />

    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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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!

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