Фон игры, оставляющий след или пятно в движении - PullRequest
0 голосов
/ 17 февраля 2020

Поэтому я пытался внедрить фон прокрутки в мою игру недавно, однако фоновый рисунок игры при перемещении влево по мере продвижения вперед оставляет огромный след, такой как:

enter image description here

Код здесь внизу:

#Game background
background = pg.transform.scale(pg.image.load('splash.jpg'), (WIDTH,HEIGHT))#background size being adjusted to fit a particular screen size
background_xpos = 0 #the x position of the background is at 0 of (0,0)
background_xpos2 = background.get_width() #obtains the width of the background at a certain coordinate 

def UpdateGame():    
    window.blit(background,(background_xpos,0))
    window.blit(background,(background_xpos,0))
    pg.display.update()

run = True  #while the game is running
while run:
    clock.tick(FPS) #determines the amount of frames per second
    background_xpos = background_xpos - 2
    background_xpos2 = background_xpos - 2

    if background_xpos < background.get_width() * -1:
        background_xpos = background.get_width()

    if background_xpos2 < background.get_width() * -1:
       background_xpos2 = background.get_width()

1 Ответ

0 голосов
/ 17 февраля 2020

Вы должны очистить экран раньше.

#Game background
background = pg.transform.scale(pg.image.load('splash.jpg'), (WIDTH,HEIGHT))#background size being adjusted to fit a particular screen size
background_xpos = 0 #the x position of the background is at 0 of (0,0)
background_xpos2 = background.get_width() #obtains the width of the background at a certain coordinate 

def UpdateGame():    
    window.blit(background,(background_xpos,0))
    window.blit(background,(background_xpos,0))
    pg.display.update()

run = True  #while the game is running
while run:
    screen.fill((0,0,0))
    clock.tick(FPS) #determines the amount of frames per second
    background_xpos = background_xpos - 2
    background_xpos2 = background_xpos - 2

    if background_xpos < background.get_width() * -1:
        background_xpos = background.get_width()

    if background_xpos2 < background.get_width() * -1:
       background_xpos2 = background.get_width()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...