every seconds

Get help using Construct 2

Post » Wed May 09, 2012 5:39 pm

hi all ,
i have an enemy that spawn a bullet every 2 seconds and i have 3 enemys in screen i want first one spawn bullet then after 1 second the 2nd one spawn and 3rd after 2 seconds, so the bullets will spawn every 2seconds on all of them but there is a diffrant start time,

is there a way to do that??
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Wed May 09, 2012 5:56 pm

Have three characters that each spawn a bullet every two seconds. This should be done by a simple 'for-each' loop, while waiting two seconds. But the problem with that is, essentially, that they'll be all shooting at the same time.

So, what you need to do, is to check for when you want them to start firing. This can be done different ways, by checking the nearest enemy, and then seeing if the distance between them and the hero is less than X amount of pixels, or just to activate it when they're all on the screen. Either way, you could set up a global variable that is called 'EnemiesStartFiring'.

Before you go any further, give each enemy its own boolean variable, called 'ActivateFiring'. Make this condition as part of the 'for-each' loop mentioned above (so in the single action, it should be: for-each ENEMY | Wait 2.0 Seconds | Enemy.ActivateFiring = true.

Anyway, when EnemiesStartFiring = 1, make an action that sets the ActivateFiring of the closest enemy to be true. Then have the System wait 1 second, and set the second enemy's ActivateFiring to be true. Then, have it wait an additional second before setting the third enemy's ActivateFiring true. Make sure you set EnemiesStartFiring to 0, otherwise that will continue to loop.

Does that make sense?

In one of my combat games, I simply have each enemy attack whenever they're within a certain range of the hero. It works well enough, but there's no coordination between the enemies.
B
14
S
1
G
2
Posts: 85
Reputation: 2,810

Post » Wed May 09, 2012 9:58 pm

@brockatkinson
i think if i did all of what you said it will work but the problem in the first step i sticked , the problem is when i made these

i couldn't try my game everytime i try to preview it ,it crash and say reload... (im using chrome).

is there a problem of what i have done? just tell me how to create the loop thingy , thanks for the help^^
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Post » Thu May 10, 2012 6:35 am

I think it's your While loop which is the trouble.

Instead of the While, replace that with System.Every X Seconds (2 seconds). Then give it a go.
B
14
S
1
G
2
Posts: 85
Reputation: 2,810


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 36 guests