pygame.mouse.get_pos()..... x / y共同定位不更新

时间:2015-04-26 04:38:47

标签: pygame coordinates python-idle

当鼠标移过时,尝试让盒子改变颜色。我遇到的问题是鼠标坐标没有更新。所以程序不知道鼠标在特定位置上。如何让它保持更新鼠标坐标?

def start_screen():
    game_display.blit(selection_screen,(0,0))
    #buttons

    mouse = pygame.mouse.get_pos()
    print(mouse)
    if 200 + 100 > mouse[0] > 200 and 550 + 50 > mouse[1] > 550:
        pygame.draw.rect(game_display,black,(200,550,100,50))
    else:
        pygame.draw.rect(game_display,white,(200,550,100,50))
    pygame.draw.rect(game_display,white,(700,550,100,50))

    pygame.display.update()

start_screen()

1 个答案:

答案 0 :(得分:1)

修好了......

def start_screen():

    intro = True
    while intro:
        for event in pygame.event.get():

            game_display.blit(selection_screen,(0,0))
            #buttons

            mouse = pygame.mouse.get_pos()

            if 200 + 100 > mouse[0] > 200 and 550 + 50 > mouse[1] > 550:
                pygame.draw.rect(game_display,black,(200,550,100,50))
            else:
                pygame.draw.rect(game_display,white,(200,550,100,50))

            pygame.draw.rect(game_display,white,(700,550,100,50))

            pygame.display.update()

start_screen()