title: How can I limit my sprite update rate?
body: <p>I'm creating a small RPG worl with pygame. So far so good, I load my maps with Tiled TMX entity manager, and everything is great. Except one thing. When my main character moves, the sprite animation is going to damn fast and I don't know what to do to avoid that. Here is my update() code :</p>
  
  <pre><code>def update(self):
          self.index += 1
          if self.index &gt;= 2:
              self.index = 0
          if self.direction == DIRECTIONS['down']:
              self.image = self.down_anim[self.index]
          elif self.direction == DIRECTIONS['up']:
              self.image = self.up_anim[self.index]
          elif self.direction == DIRECTIONS['left']:
              self.image = self.left_anim[self.index]
          elif self.direction == DIRECTIONS['right']:
              self.image = self.right_anim[self.index]
  </code></pre>
  
  <p>And my keyboard event management :</p>
  
  <pre><code>key=pygame.key.get_pressed() 
          try:
              event = pygame.event.wait()
              if event.type == KEYDOWN:
                  if (event.key == K_LEFT):
                      if angus.direction != DIRECTIONS['left']:
                          angus.direction = DIRECTIONS['left']
                      angus.update()
                      angus.position.x -= 1
                  elif (event.key == K_RIGHT):
                      if angus.direction != DIRECTIONS['right']:
                          angus.direction = DIRECTIONS['right']
                      angus.update()
                      angus.position.x += 1
                  elif (event.key == K_UP):
                      if angus.direction != DIRECTIONS['up']:
                          angus.direction = DIRECTIONS['up']
                      angus.update()
                      angus.position.y -= 1
                  elif (event.key == K_DOWN):
                      if angus.direction != DIRECTIONS['down']:
                          angus.direction = DIRECTIONS['down']
                      angus.update()
                      angus.position.y += 1
  </code></pre>
  
  <p>I'm using a clock to force 60fps. Is there a way I can tell pygame for example : update the sprite but only if it has been more than 1 second since the last update ?<br>
  Thanks</p>
  
  <p>EDIT : Solution :</p>
  
  <pre><code>def update(self):
          self.timer += 1
          if self.timer &gt;= self.UPDATE_TIME:
              self.index += 1
              self.timer = 0
              if self.index &gt;= 2:
                  self.index = 0
              if self.direction == DIRECTIONS['down']:
                  self.image = self.down_anim[self.index]
              elif self.direction == DIRECTIONS['up']:
                  self.image = self.up_anim[self.index]
              elif self.direction == DIRECTIONS['left']:
                  self.image = self.left_anim[self.index]
              elif self.direction == DIRECTIONS['right']:
                  self.image = self.right_anim[self.index]
  </code></pre>