如何在 pygame 中将透明方块变成按钮?

问题描述

for tile_x in range (0,825,15):
    for tile_y in range (0,600,15):
        tile = pygame.Surface((15,15))
        tile.set_alpha(0)
        tile.fill((255,255,255))
        disPLAYSURF.blit(tile,(tile_x,tile_y))
        # pygame.draw.rect(disPLAYSURF,(255,100),tile_y,15,15),1)


game_running = True

while game_running == True:
    for event in pygame.event.get():
        if event.type == MOUSEBUTTONDOWN:
            mouseX,mouseY = event.pos
            if tile.collidepoint(mouseX,mouseY):
                tile.set_alpha(128)
        if event.type == pygame.QUIT:
            game_running = False
            print ("program closed")

    pygame.display.update()
pygame.quit()

我尝试这样做,但错误消息说 pygame.Surface 没有“碰撞点”属性

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)