我正在制作一个游戏,在标题画面上,当我在坐标278,365处悬停时按下返回键时,我想让它显示新背景(background1)。如何制作它以便当我在这些坐标处按Enter键时,它会删除当前背景并将其替换为新的background1?
screen=pygame.display.set_mode((1024,768),0,32)
background=pygame.image.load(bif).convert()
background1=pygame.image.load(wi1).convert()
cursor=pygame.image.load(mif).convert_alpha()
x,y =278,365
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_DOWN:
x=420
y=508
elif event.key == K_UP:
x=278
y=365
elif event.key == K_RETURN and x==420 and y==508:
pygame.quit()
sys.exit()
elif event.key == K_RETURN and x==278 and y==365:
screen.blit(background, (0,0))
screen.blit(cursor, (x,y))
pygame.display.update()
答案 0 :(得分:1)
# your code
while True:
for event in pygame.event.get():
# more of your code
elif event.key == K_RETURN and x==420 and y==508:
pygame.quit()
sys.exit()
elif event.key == K_RETURN and x==278 and y==365:
#just blit the other image on top of it over it
screen.blit(background1, 0, 0)
else:
#no action performed for other background, set normal background
screen.blit(background, (0,0))
screen.blit(cursor, (x,y))
pygame.display.update()
我没有时间测试它,但我希望它有效:)