title: Speed of an object in pygame?
body: <p>I am writing a simple pygame program that only consists of moving a box around the screen. The box moves very fast and I want to know how to control the speed. In my code the updated position is moved by 1 and not smaller because if the number is not an integer it makes things more complicated.</p>
  
  <pre><code>import os, sys
  import pygame
  from pygame.locals import *
  
  pygame.init()
  mainClock = pygame.time.Clock()
  
  WINDOWWIDTH = 400
  WINDOWHEIGHT = 400
  windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
  pygame.display.set_caption("Box")
  
  BLACK = (0, 0, 0)
  RED = (255, 0, 0)
  WHITE = (255, 255, 255)
  size1 = 20
  size2 = 2
  #character = pygame.Rect(30, 30, 20, 30)
  player = pygame.Surface((40,40))
  
  
  
  
  pos1 = 100
  pos2 = 100
  
  
  MOVESPEED = 6
  
  x = 1
  
  while True:
      if pos1 == WINDOWWIDTH - 40 and pos1 &gt; 0:
          pos1 -= 1
          x += 1
      elif pos1 &lt; WINDOWWIDTH - 40 and x == 1:
          pos1 += 1
      elif x ==2:
          pos1 -= 1
  
  
      for event in pygame.event.get():
          if event.type == QUIT:
              pygame.quit()
              sys.exit()
          if event.type == KEYDOWN:
              if event.key == K_LEFT:
  
                  pos1 -= 5
              if event.key == K_RIGHT:
                  pos1 += 4
  
  
      windowSurface.fill(WHITE)
  
      #screen.blit(character)
  
  
  
      windowSurface.blit(player, (pos1, pos2))
      pygame.display.update()
  </code></pre>