Python 移动游戏背景而不是重新绘制自身
所以我试着制作一个移动的背景,但是背景并不是一直在移动。它显示了一个黑屏,背景并没有不断地闪烁,给人一种背景在移动的印象Python 移动游戏背景而不是重新绘制自身,python,background,pygame,Python,Background,Pygame,所以我试着制作一个移动的背景,但是背景并不是一直在移动。它显示了一个黑屏,背景并没有不断地闪烁,给人一种背景在移动的印象 #游戏背景 background=pg.transform.scale(pg.image.load('splash.jpg'),(宽度、高度))#调整背景大小以适应特定屏幕大小 背景_xpos=0#背景的x位置在(0,0)的0处 background_xpos2=background.get_width()#获取特定坐标下的背景宽度 def UpdateGame(): bl
#游戏背景
background=pg.transform.scale(pg.image.load('splash.jpg'),(宽度、高度))#调整背景大小以适应特定屏幕大小
背景_xpos=0#背景的x位置在(0,0)的0处
background_xpos2=background.get_width()#获取特定坐标下的背景宽度
def UpdateGame():
blit(背景(背景,0))
blit(背景(背景,0))
pg.display.update()
运行=正确#当游戏运行时
运行时:
屏幕填充((0,0,0))
时钟。滴答声(FPS)#决定每秒的帧数
background\u xpos=background\u xpos-2
background\u xpos2=background\u xpos-2
如果background\u xpos
在UpdateGame
中有一个输入错误。将UpdateGame
第2行中的background\u xpos
更改为background\u xpos2
:
window.blit(后台(后台,0))
window.blit(背景(背景)
背景灯亮起background\u xpos
两次。但它永远不会在后台\u xpos2
我该如何解决这个问题,先生(这是UpdateGame
中的一个输入错误。将background\u xpos
更改为background\u xpos2
,位于UpdateGame
#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()