0
\$\begingroup\$

Thats my problem on the Picture...The stripes

My Problem How can i fix that?

My Code:

import pygame, sys from pygame.locals import *

pygame.init()

sound = pygame.mixer.Sound('start.wav') sound.play()

size = width, height = 1600, 848 speed = [2, 2] black = (0, 0, 0)

pygame.mouse.set_cursor(*pygame.cursors.broken_x)

screen = pygame.display.set_mode(size) background = pygame.image.load("background.PNG") dragon1 = pygame.image.load("dragon1.gif") screen.blit(background, (0,0))

x,y=0,0 clock=pygame.time.Clock() speed=250 movex, movey=0,0

while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type==KEYDOWN: if event.key==K_a: movex=-1 elif event.key==K_d: movex=+1 elif event.key==K_w: movey=-1 elif event.key==K_s: movey=+1 if event.type==KEYUP: if event.key==K_a: movex=0 elif event.key==K_d: movex=0 elif event.key==K_w: movey=0 elif event.key==K_s: movey=0 x+=movex y+=movey

screen.blit(dragon1, (x,y))
pygame.display.flip()
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

You need to blit the background image at each update or loop in your mainloop like so:

while True:
    #mainloop stuff
    screen.blit(background, (0,0))
    screen.blit(dragon1, (x,y))
    pygame.display.flip()

The way you are currently doing it you are only blitting the BG once then you are blitting the dragon but the screen isnt being refreshed so you keep seeing each place the dragon was blitted at before

\$\endgroup\$
2
  • \$\begingroup\$ Thx! :) that works. but now the dragon is realy slow... \$\endgroup\$ Apr 27, 2014 at 6:56
  • \$\begingroup\$ and another problem is, when i press two keys together, the dragon moves without stop... \$\endgroup\$ Apr 27, 2014 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .