How do I spawn sprites in sequence?

Get help using Construct 2

Post » Tue Jul 07, 2015 9:12 pm

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.
B
6
S
2
Posts: 34
Reputation: 512

Post » Tue Jul 07, 2015 9:36 pm

You can try to use instance variables with a sprite in each location
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Post » Wed Jul 08, 2015 8:27 pm

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

I'm sure its not the best or most efficient way of doing it, but it works!
B
6
S
2
Posts: 34
Reputation: 512

Post » Wed Jul 08, 2015 9:11 pm

You can use this
It's not the best solution but it's more controllable and customizable than your code.
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Post » Wed Jul 08, 2015 10:04 pm

B
66
S
24
G
7
Posts: 1,513
Reputation: 11,037

Post » Wed Jul 08, 2015 10:13 pm

good way as usual @korbaach (but perhaps more complicated to understand for a beginner.)
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Post » Fri Jul 10, 2015 7:46 am

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,?
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Fri Jul 10, 2015 12:43 pm

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
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Post » Fri Jul 10, 2015 5:29 pm

@madspy so question will the code go to 6/5 ? or will construct not let it do that and reset ?
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Fri Jul 10, 2015 8:25 pm

construct let the code go to 6/5 >> if var=6 then var%5=1 (6/5=1 remainder=1)
Image Image
B
25
S
14
G
136
Posts: 875
Reputation: 71,003

Next

Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Yahoo [Bot] and 26 guests