<分区>
我想在游戏中获取用户的输入(例如他们的名字),然后将其显示在屏幕上。
我尝试了模块(包括 InputBox ),但它们都不起作用。他们只是在屏幕上显示我的文字。
我想将该输入保存到一个变量。有什么办法吗?
Example:
font1 = pygame.font.SysFont("None", 30)
score = 0
text = font1.render("{}".format(score), True,(255,255,255))
...
...
if sneakeattheapple:
score += 1
text = font1.render("{}".format(score), True,(255,255,255))
...
...
screen.blit(text,(275,6))
这会将 score
变量显示在屏幕上。但是 score
已经定义了,我想用用户给定的变量来做到这一点。
EDIT: Let me be more clear. In Python we can do this:
x = input("Do you want to do this? (y/n): ")
if x == "y":
#do something
if x == "n":
#do something
这就是我想在 Pygame 中做的事情。