0

我正在制作一个游戏,并且在标题屏幕上,当我在坐标 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()
4

1 回答 1

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

我没有时间测试它,但我希望它有效:)

于 2012-12-25T00:30:19.250 回答