块出现在pygame渲染的输出中

时间:2019-02-13 23:30:48

标签: python file-io pygame

def drawHighScore(self, DISPLAYSURF, DISPLAYWIDTH, DISPLAYHEIGHT):
    LIGHTWHITE = (128,128,128)
    FONTSIZE = 14

    highScore_file = open("highscore.txt", "r")
    topScore = highScore_file.readline()
    secondScore = highScore_file.readline()
    lastScore = highScore_file.readline()
    highScore_file.close()

    DISPLAYSURF.fill((255,0,232))
    highScoreFont = pygame.font.Font('freesansbold.ttf', FONTSIZE)
    highScoreSurf = highScoreFont.render(topScore, True, LIGHTWHITE)
    highScoreRect = highScoreSurf.get_rect()
    highScoreRect.topright = (50,50)
    # highScoreRect.topright =  (DISPLAYWIDTH-len(scorelist[0]),DISPLAYHEIGHT)
    DISPLAYSURF.blit(highScoreSurf,highScoreRect)
    highScoreSurf = highScoreFont.render(secondScore, True, LIGHTWHITE)
    highScoreRect.topright = (50,50+FONTSIZE)
    DISPLAYSURF.blit(highScoreSurf,highScoreRect)

我试图在屏幕上输出一行,但是readline方法不断添加换行符。渲染的输出在每次高分之后都会保留一些数据块。我正在寻找一种将新行保留为新行或忽略新行的方法。

0 个答案:

没有答案