Moving Character in pygame Without Repeatedly Copying Image
<p>My character, like most characters, is supposed to be repeatedly replaced by the same image a few pixels over to simulate movement.  Instead, my code causes the image to be copied when I move it, and right now it's more like a drawing application than a moving character.  Can someone please tell me why this is happening and what can be done to replace the previous image? Thanks in advance.</p>

<pre><code>import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF=pygame.display.set_mode((800,800))
pygame.display.set_caption('Hola Amigos!')

pixel_one=pygame.image.load('pixel_one.png')
pixel_one=pygame.transform.scale(pixel_one, (5,5))

def pixel(pixel_onex,pixel_oney):
        DISPLAYSURF.blit(pixel_one, (pixel_onex, pixel_oney))

pixel_onex=10
pixel_oney=10

x_change=0
y_change=0

while True: #main game loop
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN: 
            if event.key == pygame.K_LEFT:
                x_change = -5
            elif event.key == pygame.K_RIGHT:
                x_change = 5
            elif event.key == pygame.K_UP:
                y_change = -5
            elif event.key == pygame.K_DOWN:
                y_change = 5

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or pygame.K_RIGHT or pygame.K_UP or pygame.K_DOWN:
                x_change=0
                y_change=0
        if event.type==QUIT:
            pygame.quit()
            sys.exit()

    pixel_onex += x_change
    pixel_oney += y_change

    pixel(pixel_onex,pixel_oney)

    pygame.display.update()
</code></pre>

<p>Before you enter the main loop, add a statement like</p>

<pre><code>background = pygame.Surface(DISPLAYSURF.get_size())
</code></pre>

<p>and then blit background onto DISPLAYSURF. At each iteration, after everything has been updated but before anything else has been drawn, blit your background onto the DISPLAYSURF to create a clean surface.</p>

python pygame