【问题标题】:How to draw a charcter to screen on pygame如何在pygame上将角色绘制到屏幕上
【发布时间】:2016-02-04 11:48:07
【问题描述】:

如何在 pygame 中将 ascii 字符绘制到屏幕上? 我所能找到的只是如何绘制一个矩形: pygame.draw.rect(screen, color, (x,y,width,height), thickness).

我想知道是否有办法在屏幕上绘制一个字符,例如“A”并让它出现在屏幕上。

谢谢。

【问题讨论】:

    标签: python pygame screen draw


    【解决方案1】:

    我会这样做:

    font = pygame.font.Font(<Font>, 36)
    text = font.render("<Char>", 1, (10, 10, 10))
    textpos = text.get_rect()
    <Surface>.blit(text, textpos)
    

    编辑:请注意,较大/较小符号之间的名称是占位符...

    【讨论】:

    • 好答案@LPK - 你能稍微扩展一下吗 - 例如,输入“”的典型值是什么? (我认为默认字体始终存在)
    • 我认为你实际上可以使用 None
    • 或者用pygame.font.SysFont()使用其中一种系统字体
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多