在Pygame中使用screen.blit时可以使用.format功能吗? [英] Can I use the .format feature when using screen.blit in Pygame?

查看:170
本文介绍了在Pygame中使用screen.blit时可以使用.format功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,最近我无法弄清楚如何使用某些x和y值在我的pygame屏幕上将列表变灰,使文本变灰为x + = 20,每次变列表时将列表中的其他所有字符串都移动20个单位.我最近在控制台上做了一些.format的打印工作,screen.blit是否有这样的功能,所以我可以在pygame窗口中使用相同的格式?在下面包含我的代码.在此先感谢:D

Heys, I recently couldnt figure out how to blit lists onto my pygame screen using certain x and y values, allowing the text to blit say x += 20, moving every other string in my list over 20 units everytime it blits. I recently did some .format stuff with printing just in the console, is there a feature like this for screen.blit so I can use the same formatting in a pygame window? Included my code underneath. Thanks in advance :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一起使用没问题.

The format is an operator on the string, so it's no problem to use it with 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 ) )

这篇关于在Pygame中使用screen.blit时可以使用.format功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆