Reputation: 125
I am having a problem with my pygame/python program. I am using 3.3. A screenshot of what is happening is at: https://i.sstatic.net/ckKbo.png
Now as you should be able to see when you move the square before dosnt refresh meaning that you leave a trail of your self across the screen. Currently I have this:
code to initiate pygame and set background
x=0 #starting cords
y=0
image = pygame.image.load(os.path.join("textures","necromancer.png")) #set image location
running=True
while running:
for event in pygame.event.get():
if event.type == QUIT:
pygame.display.quit()
running=False
break
key = pygame.key.get_pressed() #take key user presses to use in below if/elif statements
dist = 20 #amount sprite will move when one key is pressed
if key[pygame.K_DOWN]:
y += dist
elif key[pygame.K_UP]:
y -= dist
elif key[pygame.K_RIGHT]:
x += dist
elif key[pygame.K_LEFT]:
x -= dist
screen.blit(image, (x, y))
print(x)
print(y)
pygame.display.update()
Any Ideas how I can stop this happening?
Upvotes: 1
Views: 292
Reputation: 1266
Remember last position and after move repaint it.
When someone press key remember position old_x = x
and old_y = y
.
After the move repaint position on old_x
and old_y
.
Upvotes: 1