我有一个“你有一个高分,输入你的缩写”屏幕为我的游戏,它的作品。然后我决定我想要一个闪烁的光标,光标应该在首字母所在的位置,它将从首字母开始(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)
快速而肮脏:只需将highcursor设置为9并调用blink\u cursor:
当光标先递增1到10时,当计数为10时,它会绘制一个黑色矩形。已排序。你知道吗
相关问题 更多 >
编程相关推荐