【发布时间】:2020-01-16 15:51:20
【问题描述】:
所以,我的 pygame 有一个移动的背景,运行良好。现在我想添加一个障碍物(比如一块石头),它会在屏幕的底部,并且会随着背景移动。但是,图像(障碍物)在出现几秒钟后就消失了。我希望这块石头一遍又一遍地出现,然而,它并没有出现。无法弄清楚什么是错的。请帮忙,谢谢!
background = pygame.image.load('background.png')
backgroundX = 0
backgroundX2 = background.get_width()
obstacle = pygame.image.load('obstacle.png')
obstacleX = 0
obstacleX2 = obstacle.get_width()
# use procedure for game window rather than using it within loop
def redrawGameWindow():
# background images for right to left moving screen
screen.blit(background, (backgroundX, 0))
screen.blit(background, (backgroundX2, 0))
man.draw(screen)
screen.blit(obstacle, (obstacleX, 380))
screen.blit(obstacle, (obstacleX2, 380))
pygame.display.flip()
pygame.display.update()
主循环:
while run:
screen.fill(white)
clock.tick(30)
pygame.display.update()
redrawGameWindow() # call procedure
obstacleX -= 1.4
obstacleX2 -= 1.4
if obstacleX < obstacle.get_width() * -10:
obstacleX = obstacle.get_width
if obstacleX2 < obstacle.get_width() * -10:
obstacleX2 = obstacle.get_width()
【问题讨论】:
-
请详细说明,谢谢:)
-
我尝试通过 redrawGameWindow 显示更新。我应该怎么做呢?谢谢:)
标签: python background pygame character