首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在pygame中使用平铺和pytmx的透明平铺的问题

在pygame中使用平铺和pytmx的透明平铺的问题
EN

Stack Overflow用户
提问于 2020-03-02 22:15:32
回答 1查看 397关注 0票数 2

我不能让pytmx在pygame中正确地从平铺渲染透明的瓷砖。在此示例中,您可以看到从tmx文件渲染的磁贴显示为黑色背景,我希望它像直接从图像文件渲染的图像一样。

我尝试过修改.convert().convert_alpha(),甚至设置了pygame.SCRALPHA标志,但都没有成功。

下面是一个链接,用于获取用于重现示例的资源:https://filebin.net/yvmr5jz04j889mlx

示例代码如下:

代码语言:javascript
复制
import pygame
import pytmx


pygame.init()
gameScreen = pygame.display.set_mode((280, 210))
clock = pygame.time.Clock()

# filling in white to see the lack of alpha
gameScreen.fill((255, 255, 255))

# bliting from tmx file, (the alpha is not recognized)
gameMap = pytmx.load_pygame('test_map.tmx')
for layer in gameMap.visible_layers:
    if isinstance(layer, pytmx.TiledTileLayer):
        for x, y, gid, in layer:
            tile = gameMap.get_tile_image_by_gid(gid)
            if tile:
                gameScreen.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight))

# bliting the image directly from pygame (the alpha is correctly recognized)
rock = pygame.image.load('rock.png')
gameScreen.blit(rock, (140, 70))


def game_loop():
    gameExit = False
    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
        pygame.display.update()
        clock.tick(30)


game_loop()
pygame.quit()
EN

回答 1

Stack Overflow用户

发布于 2020-03-02 23:41:40

找到解决方案了!

原来,当我在Tilesets中创建Tilesets时,我选中了“使用透明颜色”复选框。我花了很长时间才弄明白这一点,因为当我在创建磁贴集后查看磁贴中的磁贴集属性时,它显示没有设置透明度颜色,并且在磁贴中考虑了透明度。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60490707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档