Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 清除pygame曲面中光标所在的部分_Python_Cursor_Pygame_Surface - Fatal编程技术网

Python 清除pygame曲面中光标所在的部分

Python 清除pygame曲面中光标所在的部分,python,cursor,pygame,surface,Python,Cursor,Pygame,Surface,我有一个“你有一个高分,输入你的首字母”屏幕,我的游戏,它的工作。然后我决定我想要一个闪烁的光标,光标应该在首字母所在的位置,它将从首字母开始(x,y),然后当输入时,移动到首字母2(x,y)。问题是,如果你在光标画出蓝色矩形时按下一个字母,它就会留在屏幕上,我只需要清除这个区域。有办法做到这一点吗?这是我的初始输入代码和光标闪烁代码: def update_highscores(index): background.fill(BLACK) # co-ords for ini

我有一个“你有一个高分,输入你的首字母”屏幕,我的游戏,它的工作。然后我决定我想要一个闪烁的光标,光标应该在首字母所在的位置,它将从首字母开始(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)
def更新_高分(索引):
背景。填充(黑色)
#初始条目的co ords
ix=[]
ix1=(background.get_width()/2)-25
ix2=ix1+20
ix3=ix2+20
九、附加(ix1)
九、附加(ix2)
九、附加(ix3)
iy=140
inits=[]
initsurf=[]
title=“你的分数很高”
textsurface=写入(标题)
blit(textsurface,((background.get_width()/2)-(textsurface.get_width()/2),60))
enterinits=“输入您的姓名首字母”
textsurface=write(enterinits)
blit(textsurface,((background.get_width()/2)-(textsurface.get_width()/2),90))
屏幕光点(背景,(0,0))
pygame.display.flip()
对于范围(3)内的c:
字母=-1
而字母==-1:
闪烁光标(ix[c],iy)
屏幕光点(背景,(0,0))
pygame.display.flip()
时钟滴答作响(25)
字母=getkey()
屏幕光点(背景,(0,0))
pygame.display.flip()

如果字母又快又脏:只需将highcursor设置为9并调用blink\u cursor:

if letter <= 127:
        inits.append(chr(letter).upper())
        highcursor = 9
        blink_cursor(ix[c], iy)
        screen.blit(background, (0, 0))
        pygame.display.flip()
if字母