Pygame - Smoother Movement
<p>I have added an Object/Image on the <code>main_screen</code>, the object is called <code>cancer_cell</code>. 
What I'm trying to do here is that I want the object move smoothly. I have to repeatedle press on the arrow keys to keep it moving. 
How do I make it move <code>while</code> arrow keys are pressed ?  </p>

<p>here's the code:</p>

<pre><code>exitgame = False
cellpos_x = 0
cellpos_y = cancer_cell.get_rect().height*2
while not exitgame:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exitgame = True
            quitgame()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                cellpos_x -= 10
            if event.key == pygame.K_RIGHT:
                cellpos_x += 10


    gameplay_bg = pygame.image.load("/Users/wolf/Desktop/python/img/gameplay_bg.png").convert()
    main_screen.fill(white)
    main_screen.blit(gameplay_bg, [0,0])
    main_screen.blit(cancer_cell, [cellpos_x, cellpos_y])
    pygame.display.flip()
    clock.tick(20)
</code></pre>

<p>someone told me to try the solution at <a href="http://stackoverflow.com/questions/25494726/how-to-use-pygame-keydown">How to use pygame.KEYDOWN</a>:
but that didn't work either. Or maybe i did it wrong:</p>

<pre><code>if event.type == pygame.KEYDOWN:
    key_pressed = pygame.key.get_pressed()
    if key_pressed[pygame.K_LEFT]:
        cellpos_x -= 10
    if key_pressed[pygame.K_RIGHT]:
        cellpos_x += 10
</code></pre>

<p><strong>PROBLEM SOLVED</strong></p>

<p>I have solved the problem by just unindenting this part from the <code>FOR</code> loop
    while not exitgame:</p>

<pre><code>    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exitgame = True
            quitgame()

    key_pressed = pygame.key.get_pressed()
    if key_pressed[pygame.K_LEFT]:
        cellpos_x -= 10
    if key_pressed[pygame.K_RIGHT]:
        cellpos_x += 10
</code></pre>

python pygame