while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
elif event.type == pygame.MOUSEBUTTONDOWN:
is_inside = my_rect.collidepoint(pygame.mouse.get_pos())
print is_inside
if is_inside == 1:
myfont = pygame.font.SysFont("monospace", 15)
label = myfont.render("The Penrose Triangle by Roman Formicola", 5, (black))
gameDisplay.blit(label, (300,150))
我有它的目标是,一旦你点击my_rect,消息将无限期地留在那里
答案 0 :(得分:0)
只需创建一个包含Rect
的变量(实际使用Rect
类):
my_rect = pygame.Rect(400, 300, 100, 100)
然后,您可以使用Rect
的{{3}}方法检查鼠标位置是否在my_rect
内:
...
elif event.type == pygame.MOUSEBUTTONDOWN:
is_inside = my_rect.collidepoint(pygame.mouse.get_pos())
pygame.draw.rect(gameDisplay, cyan, my_rect, 0)
...