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

时间:2018-12-18 20:23:32

标签: python printing pygame format blit

嘿,最近我无法弄清楚如何使用某些x和y值在我的pygame屏幕上将列表变白,使文本变白为x + = 20,每次变蓝时将列表中的其他所有字符串都移动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")

1 个答案:

答案 0 :(得分:1)

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 ) )