How do I spawn sprite instances specifically? (Continued) (SOLVED)

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Cute cartoon girl character with Walk, Jump, and Idle animations for 2D games.
  • The initial question was partially solved. However, one thing still remains:

    I'm trying to spawn the object instances in clockwise order with 1 being first, 2 second, so on and so forth. What I have for code so far is this:

    I know the second line is a repeat of the first, and is wrong, because after the first color shows, only the second color in line shows up afterwards, and what I would want is for all colors to show in sequence, regardless of the last one that shows/is attached to the main sprite (Chemic). What I had before was a "choose(1,2,3,4)," which wasn't what I was looking for, either.

    Any help, as always, is appreciated.

  • I know I sound like a broken record, repeating this in every post, but you should never use "Trigger once" condition with objects that have multiple instances! And don't use it in loops.

    If there is no parent event for the events on your screenshot, then the second line runs on every tick, changing the value of newColor variable 60+ times per second. So the color will be unpredictable when it's time to spawn a new molecule.

    Also, using "Pick last created" inside of "For each" loop doesn't make sense. And "Every tick" inside of "Every 5 seconds" is meaningless too.

    Basically, the way you organize events is wrong. The whole thing should be done in a single event or function.

  • I see you've put an example, which is helpful.

    I should have specified, however, some of the parameters I planned to have in place.

    So when the last instance of Molek is attached, or after a certain amount of time passed, I hoped to spawn another in the designated place, all dependent on what color the last one was and where it spawned, which, due to instance variables, are supposed to be one and the same.

    I say "supposed to be," because sometimes a Molek will spawn in the center of the stage, which isn't what I intended. How should I go about fixing that? And for the time factor?

    Thanks in advance!

  • So when the last instance of Molek is attached, or after a certain amount of time passed, I hoped to spawn another in the designated place, all dependent on what color the last one was and where it spawned, which, due to instance variables, are supposed to be one and the same.

    Ok, then pick the last created Molek, get all the important values from it (its position, color etc.) and save them in local variables. Then create a new Molek instance.

    This is just a mockup, I don't know how exactly you want to calculate the position for a new instance:

  • This seems to work perfectly, given the 5 second count.

    One more thing:

    So when the last molek is attached, I would hope for another to spawn. In other words, I suspect there to be an "OR" block used somewhere in the 5 second block but can't seem to figure out how to get it to spawn only once per attach.

    If 5 seconds have passed and the molek isn't attached, then another may spawn, but only up to 4 at a time.

  • Then you need a function.

    Create a function SpawnNewMolecule, move all that code into the function. When a molecule becomes attached - call the function. Every 5 seconds - also call the function.

    But if you need to wait 5 seconds after each attached molecule, then I suggest you use Timer behavior on one of the objects (with a single instance). You can add an invisible sprite just to host the timer.

    On start of layout
     : Start recurring Timer "spawn" for 5s
    
    When molecule becomes attached
     : Call SpawnNewMolecule
     : Start recurring Timer "spawn" for 5s (this will restart it from the beginning)
    
    On Timer "spawn"
     : Call SpawnNewMolecule
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's it! Works like a charm, thank you!

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