移动的游戏背景不会重绘

时间:2020-02-27 19:51:33

标签: python background pygame

因此,我正在尝试制作一个不断变化的背景,但是背景并非一直在变化。它显示黑屏,并且背景没有连续发白,给人以为背景在移动。

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:
    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()

1 个答案:

答案 0 :(得分:0)

UpdateGame 中有一个拼写错误。将 background_xpos 的第二行中的 background_xpos2 更改为 UpdateGame

window.blit(background,(background_xpos,0))

window.blit(background,(background_xpos2,0))
相关问题