Pygame怪异的Windows Blit Bug

时间:2019-04-04 23:38:40

标签: python pygame

我正在制作一个游戏,并将其转换为Windows上的.exe,但是运行时,我看到的双眼看上去比平时更厚。我还注意到,使用我制作的菜单选择器时,当它们是同一张图片时,它会制作两张图片。 https://youtu.be/GEh61ahTTPI

的样子

我尝试使菜单选择器更平滑,并尝试使用其他图片文件。

Title = pygame.image.load('Graphics/Title.png')
Play = pygame.image.load('Graphics/Play.png')
Option = pygame.image.load('Graphics/Option.png')
Exit = pygame.image.load('Graphics/Exit.png')
LinePX = pygame.image.load('Graphics/LinePX.png')
LineO = pygame.image.load('Graphics/LineO.png')
clock = pygame.time.Clock()
screen = pygame.display.set_mode((1280, 720))
screen.fill((0,0,0))
screen.set_alpha(0)
black = pygame.image.load('Graphics/black.png')
controlstart = True

y = 235
y1 = 3000

xb = 10000
yb = 10000


cnt = 0
playing = True
while playing:
    for event in pygame.event.get():
        if controlstart == True:
            if event.type == pygame.KEYDOWN:
                if event.key==pygame.K_KP_ENTER or 
event.key==pygame.K_RETURN:
                    pygame.mixer.music.stop()

                    pygame.mixer.Channel(2).play(enter_sfx)
                    y += 1
                    fade(1280, 720)
                    xb = 0
                    yb = 0
                    if y == 3236:
                        controlstart = False
                    if y == 436:
                        playing = False
                        pygame.quit()
                        quit()
                if event.key == pygame.K_UP: 
                    pygame.mixer.Channel(3).play(move_sfx)
                y += 1
                if y == 3236:
                    y = 235
                    y1 = 3000
                if y == 236:
                    y = 435
                    y1 = 3000
                if y == 436:
                    y1 =335
                    y = 3235

                if event.key == pygame.K_DOWN:   
                    pygame.mixer.Channel(4).play(move_sfx)
                    y += 1
                    if y == 236:
                        y = 3235
                        y1 = 335
                    if y == 3236:
                        y1 = 3000
                        y = 435
                    if y == 436:
                        y1 = 3000
                            y = 235

    screen.blit(Title, (360, 0))
    screen.blit(Play, (460, 250))
    screen.blit(Exit, (460, 450))
    screen.blit(LinePX, (482.5, y))
    screen.blit(LineO, (482.5, y1))
    screen.blit(Option, (460, 350))
    screen.blit(black, (xb, yb))
    pygame.display.update()
    clock.tick(FPS) 

我期望普通菜单的输出,不是厚而小故障的菜单,但结果却很奇怪。

1 个答案:

答案 0 :(得分:0)

while playing内,您应该清除屏幕-即screen.fill( (0,0,0) ),然后再绘制所有元素。这样,您将在菜单中获得选定项目的动画。

除了fill()以外,您还可以blit()删除所有元素的图像/背景。