python - 在 Pygame 中使用 screen.blit 时可以使用 .format 功能吗?

标签 python printing pygame format blit

嘿,我最近不知道如何使用某些 x 和 y 值将列表 blit 到我的 pygame 屏幕上,允许文本 blit 说 x += 20,每次 blit 时将列表中的所有其他字符串移动超过 20 个单位。我最近在控制台中做了一些打印的 .format 内容,是否有类似 screen.blit 的功能,以便我可以在 pygame 窗口中使用相同的格式?在下面包含我的代码。提前致谢:D

import pygame


NAMES = ['Deanerys T.', 'Jon S.', 'Gregor C.', 'Khal D.', 'Cersei L.', 'Jamie L.', 
         'Tyrion L.', 'Sansa S.', 'Ayra S.', 'Ned S.']

DATE_OF_BIRTH = ['6/10/1996', '6/12/1984', '3/12/1980', '8/4/1986', '7/2/1970', 
                 '7/2/1975', '12/24/1980', '11/30/1993', '5/18/1999', '6/27/1984']

AGE = [22, 34, 38, 32, 48, 43, 38, 25, 19, 34]

MARITAL_STATUS = ['Not Married', 'Not Married', 'Not Married', 'Not Married', 
                  'Married', 'Not Married', 'Married', 'Married', 'Not Married', 'Married']

NUM_OF_CHILDREN = [3, 0, 0, 4, 2, 0, 1, 1, 0, 5]




for i in range(10):
    print("{:>12} was born {:>10}, is age {:>2}.  They have {:>1} children, and are {:>4}".format(NAMES[i], DATE_OF_BIRTH[i], AGE[i], NUM_OF_CHILDREN[i], MARITAL_STATUS[i]))
print("\n")

for i in range(10):
    print("NAME: {:>12} DATE OF BIRTH: {}".format(NAMES[i], DATE_OF_BIRTH[i], ))
print("\n")

for i in range(10):
    print("NAME: {:>12}  AGE: {}".format(NAMES[i], AGE[i], ))
print("\n")

for i in range(10):
    print("NAME: {:>12} MARRIAGE STATUS: {}".format(NAMES[i], MARITAL_STATUS[i], ))
print("\n")

for i in range(10):
    print("NAME: {:>12} NUMBER OF CHILDREN: {}".format(NAMES[i], NUM_OF_CHILDREN[i], ))
print("\n")

最佳答案

format是字符串上的一个运算符,所以在pygame中使用它是没有问题的。

例如:

hp = 56
player_hp_text = "Hit Points: {:>3}".format( hp )

player_hp_bitmap = myfont.render( player_hp_text, 16, (255, 255,0) )
screen.blit( player_hp_bitmap, ( 10, 10 ) )

关于python - 在 Pygame 中使用 screen.blit 时可以使用 .format 功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53840499/

相关文章:

python - 如何修复此无效语法错误

java - SNMP:打印页数的通用 OID

java - Java中有没有不阻塞UI的打印函数?

python - 在 pygame 中执行 for 循环后,图像不会保留在屏幕上

python - 在 Windows 上,如何打开以写入另一个进程已打开以进行写入的文件?

python - RPC 的集合点以 (StatusCode.UNAVAILABLE,套接字已关闭)> 终止

python - 起始页上的 Django 注册表单,无需重定向到登录页

c# - 从 Azure Function 打印到 LAN 打印机

python - 我怎样才能从中心而不是pygame中的角落旋转图像?

python - Pygame Mixer.music无法读取mp3流