stop clock in sfml

hey guys below is a portion of the code where an enemy is created randomly on the screen after 2 seconds bt i want a max of 5 enemies on the screen but i dont knw how to stop the time.....i also tried to limit my deque to 5 but it still produces more....please help thanx in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  
// 

deque<enemy> enemyArray(5);
//
 if((Timer1.asSeconds()>=2))
            {
                clock1.restart();

                class random random1;
                enemy1.rect.setPosition(random1.random_function(screen.getSize().x), random1.random_function(screen.getSize().y));
                enemyArray.push_back(enemy1);

            } 
// 
for(deque<enemy>::iterator iter1=enemyArray.begin(); iter1!=enemyArray.end(); iter1++)
        {


            enemyArray[temp1].update();
            enemyArray[temp1].updateMovement();
            screen.draw(enemyArray[temp1].sprite);
            temp1++;
        }
Instead of stopping the clock you can check in the if statement how many enemies you have. If you have 5 or more don't create any new ones.

This line creates 5 enemies from the start:
 
deque<enemy> enemyArray(5);

If you want zero enemies at the start you should do:
 
deque<enemy> enemyArray;
Topic archived. No new replies allowed.