title: Best practices: ENTER_FRAME vs. Timer
body: <p>I'm creating a Flash game which is based on the old Pacman and I'm not sure which is the best way to control the animation.</p>
  
  <p>As I understand it these type of games were originally dependent on a game loop which ran faster or slower depending on the CPU, which is why I imagine that the most similar to use would be the ENTER_FRAME event.</p>
  
  <p>This however presents the problem of having to have a specific frame rate and changing it later is out of the question, not to mention being limited to very few different "speeds" (see below). An example could be that the sprite has to move 12 pixels before the next move is determined. If the speed is then 4 pixels per frame, the math is quite simple:</p>
  
  <pre><code>[...]
  public var stepCount:uint = 0;
  
  [...]
  
  function enterFrameHandler(e:Event):void
  {
      if(stepCount==0) {
      //Some code to evaluate next move. Let's say it evaluates to MOVE RIGHT
      }
  
      if(MOVE_RIGHT)
      {
          x += 4;
      }
  
      stepCount++;
      if(stepCount &gt; 2)
      {
          stepCount = 0; //Now ready to evaluate direction again.
      }
  }
  </code></pre>
  
  <p>This all works fine, but let's say that I want the sprite to move 5 pixels per frame. Then the number of frames before making the next evaluation would not compute. The stepSize would have to be a multiple of 12, which limits the different possible speeds (1,2,3,4 and 6 pixels per frame).</p>
  
  <p>This is why I attempted to base the movement on a Timer instead, which I also managed to get to work, but the movement was somewhat erratic and it seemed like the Timer was using far more memory than the ENTER_FRAME event. Instead of an even movement the Timer made the sprite slow down and speed up and slow down again.</p>
  
  <p>Another possible solution could be the Tween class, but it seems extravagant.</p>
  
  <p>Does anyone have experience with what works best in other games?</p>
  
  <p>Morten Twellmann</p>