title: How to spawn enemies periodically
body: <p>I am attempting to create a game where enemies will spawn randomly and move towards a point on the screen. My problem is that the program waits for them to spawn and them starts moving them. I want them to start moving as they spawn and have a short break in between each one.</p>
  
  <p>Here's the two main methods behind making them move:</p>
  
  <pre><code>public void newLevel() {
      runOnUiThread(new Runnable(){
          public void run() {
              int i = 0;
              while( i &lt; 10){
                  addSpeks();
                  i++;
                  try {
                      Thread.sleep(2000);
                  }
                  catch(InterruptedException ie){
                      ie.printStackTrace();
                  }
              }
          }
      });
  }
  
  public void addSpeks() {
      Spek newSpek = new Spek(this);
  
      setRandomRegion();
  
      newSpek.setX(spawnX);
      newSpek.setY(spawnY);
  
      relativeLayout.addView(newSpek);
      spekList.add(newSpek);
      newSpek.setOnClickListener(spekListener);
      newSpek.animate().x(finalX).y(finalY).setDuration(8000);
  }
  </code></pre>
  
  <p>Spek is a simple class which extends an ImageView and setRandomRegion() selects a random x, y coordinate on the border of the screen. I have a counter in the while loop for simplicity purposes but I would like to eventually move it to a conditional infinite loop where it only stops if you lose the game.</p>
  
  <p>Thanks for any help and let me know if the problem needs more clarification.</p>