如何在pygame

时间:2015-04-25 22:06:23

标签: python python-2.7 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()

这里我有一些文字告诉用户点击Enter继续。我想知道我怎么能只把一个字符串索引blit,例如我可以blit
StoryFont [1]并且只会向屏幕显示'l'。我确实试过这个并没有用。谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

据我所知,你无法编辑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))

希望这会有所帮助。