我有一个想法,在我的类似ASCII的游戏机游戏中使用汉字作为实体。我正在使用python-tcod,但我不知道是否有在其中使用中文字符的方法。
我试着通过console_set_custom_font函数设置中文字体,它在显示英文字符方面效果很好,但显示中文字符效果不佳。它们就是不显示。
libtcod.console_set_custom_font('GoJuOn.TTF', libtcod.FONT_TYPE_GREYSCALE)
libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False, libtcod.RENDERER_SDL2)我试着让我的角色看起来像你,但得到了这个。(您可以看到角色通过它的FOV移动,以及它如何覆盖项目。)

例如,这就是它以前的工作方式。
源代码取自libtcod python tutorial
更新:我尝试对gb18030、gbk、gb2312、hz、cp950、bi0ghkscs、big5、iso2022_jp_2编码使用'你'.encode(),但它输出了错误的符号。例如,段落符号或tilda ('~'),或者上面有点的几个字母。
upd2:我尝试使用另一种编码的代码
player = Entity(0, 0, '你'.encode('gb18030'), libtcod.white, 'Player',
render_order=RenderOrder.ACTOR, blocks=True,
fighter=fighter_component, inventory=inventory_component, level=level_component)呈现字符的通用代码('你‘字符是实体的字符属性)
def draw_entity(con, entity, fov_map, game_map):
if libtcod.map_is_in_fov(fov_map, entity.x, entity.y) or (entity.stairs and game_map.tiles[entity.x][entity.y].explored):
libtcod.console_set_default_foreground(con, entity.color)
libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)发布于 2019-04-27 23:56:23
https://stackoverflow.com/questions/55882197
复制相似问题