有两个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
在处理前一个调用的事件时再次调用
pygame.event.get()
通常不会起作用。从您的代码中不清楚您要实现什么。但是,我建议您在内部for event
循环中存在冲突时,将处理pygame.MOUSEBUTTONDOWN
事件的代码移动到外部循环(并完全删除内部for event
循环)。在我的意思是(当然是未经测试的):
相关问题 更多 >
编程相关推荐