pygame.event.get()的多个实例

时间:2016-05-22 14:15:58

标签: python events pygame

有两个for event in pygame.event.get():个实例。它在第二个内部不起作用。我想两次调用该函数是行不通的。这应该做什么?顺便说一下,这是一个在棋盘游戏中将棋子从正方形移动到正方形的功能。

def movement_one(blit1,charac1,screen,squareblitter,boardcoord,placecheck_True):
    global mouse1, mouse1_des
    run1=True
    while run1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse1 = pygame.mouse.get_pos()
                for i in range(80):
                    if squareblitter[i].collidepoint(mouse1):
                        collided = i
                        break
                print "wow"
                print i
                print collided in placecheck_True
                if collided in placecheck_True:
                    #checks if the square is occupied or not
                    print "wiw"
                    for event in pygame.event.get():
                        print "wtf"
                        if event.type == pygame.QUIT:
                            exit()
                        elif event.type == pygame.MOUSEBUTTONDOWN:
                            mouse1_des = pygame.mouse.get_pos()
                            print "omg"
                            squareblitter[i]
                            pygame.display.update()
                            for i in range(80):
                                if squareblitter[i].collidepoint(mouse1_des):
                                    screen.blit(placecheck_True[collided], squareblitter[i])
                                    placecheck_True.update[i]=placecheck_True[collided]
                                    pygame.display.update()
                                    run1=False
                                    break
                else:
                    break

1 个答案:

答案 0 :(得分:0)

在处理之前通话中的活动时再次致电pygame.event.get()通常无法正常工作。从您的代码中可以清楚地了解到您正在尝试完成的任务。但是,我建议你移动代码来处理pygame.MOUSEBUTTONDOWN事件,当你在内部for event循环中发生碰撞到外部时(并移除内部{{} 1}}完全循环)。

这就是我的意思(当然未经测试):

for event