在坐标文本时,Y坐标更新但不显示

时间:2015-11-24 22:03:53

标签: python-3.x pygame blit

我有一个程序,用于在屏幕上滚动数字/字母,就像在电影" The Matrix"中一样。当其中一列到达用户名称中的字母(由用户输入找到)时,它会冻结,该列中的所有其他字符都会消失。程序打开正确,但只会在零y坐标处打印字符。这是将字母和数字加到屏幕上的功能。当我插入一个print语句以检查它是否在右y坐标处打印字母时,它表示它正在递增32像素,就像它应该的那样。

for sym in lst:
    symbol = matrixfont.render(sym, True, (0, 255, 0))
    print("Printing %s" % sym)
    print("x coord is %s and y coord is %s" % (x_coord, i))
    screen.blit(symbol, (x_coord * 30, i))
    pygame.display.update()
    i -= spacing

它只打印y坐标0处的所有字母,但是打印以校正x坐标。也许完整的代码会有所帮助:

import time
import random
import pygame
pygame.init()

#----------DEFINING VARIABLES

user_name = input("Type in your first name.")
spacing = 32
symbol_list = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
               "V", "w", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
background_color = 0, 0, 0
master_list = []
matrixfont = pygame.font.Font("C:/Python34/Programs/MatrixSpeller/OCRAEXT.TTF", spacing)
pressedkey = pygame.key.get_pressed()
windowwidth = len(user_name) * 30

#----------SETTING UP WINDOW

screen = pygame.display.set_mode((windowwidth, 300))
pygame.display.set_caption('Name Speller')
screen.fill(background_color)

#----------DEFINING FUNCTIONS


def update_list(x):
    print("update list %s" % x)
    s = random.choice(symbol_list)
    lststring = master_list[x]
    lststring = s + lststring[:9]
    master_list[x] = lststring


def print_list(lst, x_coord):
    global i
    i = 0
    for sym in lst:
        symbol = matrixfont.render(sym, True, (0, 255, 0))
        print("Printing %s" % sym)
        print("x coord is %s and y coord is %s" % (x_coord, i))
        screen.blit(symbol, (x_coord * 30, i))
        pygame.display.update()
        i -= spacing

#----------MAIN LOOP

for n in range(len(user_name)):
    master_list.append("@")
    print("master list is %s" % master_list)

while True:
    for n in range(len(user_name)):
        update_list(n)
        print_list(master_list[n], n)

0 个答案:

没有答案