我的游戏中有一个“你得分高,输入你的名字缩写”屏幕,它有效。然后我决定我想要一个闪烁的光标,其中首字母将是,并且它将从初始的一个(x,y)开始,然后当输入时,移动到初始2(x,y)。问题是,如果你在光标绘制蓝色矩形时按下一个字母,它会将其留在屏幕上,我需要清除该区域。有没有办法做到这一点?这是我的初始输入代码和光标闪烁代码:
def update_highscores(index):
background.fill(BLACK)
# co-ords for inital entry
ix = []
ix1 = (background.get_width()/2) - 25
ix2 = ix1 + 20
ix3 = ix2 + 20
ix.append(ix1)
ix.append(ix2)
ix.append(ix3)
iy= 140
inits = []
initsurf = []
title = "You have a high score"
textsurface = write(title)
background.blit(textsurface, ( (background.get_width()/2) - (textsurface.get_width()/2), 60))
enterinits = "enter your initials"
textsurface = write(enterinits)
background.blit(textsurface, ( (background.get_width()/2) - (textsurface.get_width()/2), 90))
screen.blit(background, (0, 0))
pygame.display.flip()
for c in range(3):
letter = -1
while letter == -1:
blink_cursor(ix[c], iy)
screen.blit(background, (0, 0))
pygame.display.flip()
clock.tick(25)
letter = getkey()
screen.blit(background, (0, 0))
pygame.display.flip()
if letter <= 127:
inits. append(chr(letter))
elif inkey == K_RETURN:
break
initsurf.append(write(inits[c]))
background.blit(initsurf[c], (ix[c], iy))
screen.blit(background, (0, 0))
pygame.display.flip()
initStr = inits[0] + inits[1] + inits[2]
highnames[index] = initStr
def blink_cursor(x,y):
global highcursor
highcursor +=1
highcursor = highcursor%11
if highcursor == 5:
pygame.draw.rect(background, BLUE, (x, y, 20, 20), 0)
elif highcursor == 10:
pygame.draw.rect(background, BLACK, (x, y, 20, 20), 0)
答案 0 :(得分:0)
快速和脏:只需将highcursor设置为9并调用blink_cursor:
if letter <= 127:
inits.append(chr(letter).upper())
highcursor = 9
blink_cursor(ix[c], iy)
screen.blit(background, (0, 0))
pygame.display.flip()
当blink_cursor首先将光标计数增加1到10时,当计数为10时,它会绘制一个黑色矩形。排序。