How do I spawn sprites in sequence?

  • Hi all

    Working on my first game and learning as I go along. The forums have been very useful, along with the tuts. I've searched, and though I have found many questions and answers on spawning sprites, I've not been able to find a solution for this problem I have:

    I have 5 spawn positions: A B C D E

    Spawn location A will spawn a sprite. Once this sprite stops moving, location B will spawn a sprite. Once this sprite stops moving, location C will spawn a sprite and so on. Once the Sprite spawned by location E has stopped moving, the spawning cycle must go back to location A, and start all over again, until a certain condition is met.

    I have tried a variant of the answer given here : https://www.scirra.com/forum/every-seconds_t69711 , but I find that location A keeps spawning over and over, and the other locations do not spawn at all. The solution in that post is also time dependent. I would prefer to spawn a new sprite once the previously spawned one has stopped moving.

    Thanks to anyone offering some help or guidance.

  • You can try to use instance variables with a sprite in each location

  • Ah ... you got me thinking and I figured out a way that works for me. What I did was define a global variable (which I called LoopRun with initial value of 0) whose value I changed after each spawn.

    Here's the code.

    I'm sure its not the best or most efficient way of doing it, but it works!

  • You can use this

    It's not the best solution but it's more controllable and customizable than your code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • good way as usual korbaach (but perhaps more complicated to understand for a beginner.)

  • I hate to bump this but I must ask....

    How does Korbaach's event sheet work?

    I almost understood it for a moment, and then I feel like I took 5 steps back.

    So the layout starts, and then the system grabs all the Spawn1 objects, gives its instance variable a number = it's own IID, so they're all different.

    Then every second, the system grabs the Spawn1 object, only if the instance variable matches the global variable...

    It then proceeds to spawn the sprite, which has bullet and destroy on outside of layout - Why does the animation frame need to be set to spawn?

    And the big question is, where the system sets spawn to (Spawn+1)%5 , what is the %5 for?

    Is it because there are 5 Spawn1 Objects, so the system adds one, and then.. err.. does what with the %5?

    How does the system cycle back to 1? I'm assuming it has something to do with the %5? Then it goes 1,2, 3, 4, 5, then after 5 it resets to 1? Or in this case, what would be 0,1,2,3,4,?

  • When creating the animation changes; it is to show the sprite may be different depending on the spawner... it's optional

    % (modulo, remainder after division) https://www.scirra.com/manual/78/expressions

    In his example , you have 4 clone of spawn1. their IID range from 0 to 4.

    At the end of the loop, you increment by 1 your variable and you divide by 5 and you keep the remainder of your division (eg: 5%5=0 (5/5=1 remainder= 0))

    Your variable is range from 0 to 4 as your IID of spawn1

  • MadSpy so question will the code go to 6/5 ? or will construct not let it do that and reset ?

  • construct let the code go to 6/5 >> if var=6 then var%5=1 (6/5=1 remainder=1)

  • Since I'm not good with words..

    ( MadSpy Thanks for assistance )

    Capx Code go like this:

    How is 3 modulo 5 = 3

    The Modulus Operator

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