如何在 pygame 中将文本的特定索引 blit 到屏幕
How do I blit specific indexes of text to the screen in pygame
import pygame
import math
def StoryLine():
pygame.init()
width = 1104
height = 644
white = 255,255,255
red = 255,0,0
color = 255,0,0
black = 0,0,0
cyan = 0,255,255
gameDisplay = pygame.display.set_mode((width,height))
pygame.display.set_caption('War Games 3')
Map = pygame.image.load('Map3Cut.png')
Map = pygame.transform.scale(Map, (1104,644))
stop = False
while not stop:
gameDisplay.blit(Map, (0,0))
StoryText = pygame.font.SysFont("monospace",25)
StoryFont = StoryText.render('Click ENTER to continue...',5,(red))
gameDisplay.blit(StoryFont,(50,500))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
mainGame()
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
这里我有一些文字告诉用户点击回车键继续。我想知道如何只对字符串的一个索引进行 blit,例如我可以 blit
StoryFont[1] 并且只会将 'l' 传送到屏幕。我确实试过了,但没有用。感谢您的帮助。
据我所知,您无法编辑 pygame 渲染实例。但是,您可以创建一个包含普通字符串的变量,然后呈现它。例如:
while not stop:
original_txt = 'Click ENTER to continue...'
text_to_be_displayed = original_txt[1]
gameDisplay.blit(Map, (0,0))
StoryText = pygame.font.SysFont("monospace",25)
StoryFont = StoryText.render(text_to_be_displayed,5,(red))
gameDisplay.blit(StoryFont,(50,500))
希望对您有所帮助。
import pygame
import math
def StoryLine():
pygame.init()
width = 1104
height = 644
white = 255,255,255
red = 255,0,0
color = 255,0,0
black = 0,0,0
cyan = 0,255,255
gameDisplay = pygame.display.set_mode((width,height))
pygame.display.set_caption('War Games 3')
Map = pygame.image.load('Map3Cut.png')
Map = pygame.transform.scale(Map, (1104,644))
stop = False
while not stop:
gameDisplay.blit(Map, (0,0))
StoryText = pygame.font.SysFont("monospace",25)
StoryFont = StoryText.render('Click ENTER to continue...',5,(red))
gameDisplay.blit(StoryFont,(50,500))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
mainGame()
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
这里我有一些文字告诉用户点击回车键继续。我想知道如何只对字符串的一个索引进行 blit,例如我可以 blit
StoryFont[1] 并且只会将 'l' 传送到屏幕。我确实试过了,但没有用。感谢您的帮助。
据我所知,您无法编辑 pygame 渲染实例。但是,您可以创建一个包含普通字符串的变量,然后呈现它。例如:
while not stop:
original_txt = 'Click ENTER to continue...'
text_to_be_displayed = original_txt[1]
gameDisplay.blit(Map, (0,0))
StoryText = pygame.font.SysFont("monospace",25)
StoryFont = StoryText.render(text_to_be_displayed,5,(red))
gameDisplay.blit(StoryFont,(50,500))
希望对您有所帮助。