所以我最近一直在尝试在游戏中实现滚动背景,但是当我向前移动时,游戏背景移到左侧会留下很大的痕迹,例如:
代码在下面:
#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()
#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()