【问题标题】:Invalid destination position for blit errorblit 错误的目标位置无效
【发布时间】:2020-08-25 16:09:54
【问题描述】:

我收到了这个错误。这是完整的回溯。

Traceback (most recent call last):
File "C:/Users/hobin/PycharmProjects/codeitPython/Snake_game.py", line 103, in <module>
snakegame()
File "C:/Users/hobin/PycharmProjects/codeitPython/Snake_game.py", line 52, in snakegame
dis.blit(value, round(display_width / 3), round(display_height / 5))
TypeError: invalid destination position for blit

这是与错误相关的代码

while not game_over:
    while game_end == True:
        #For displaying the score
        score = Length_of_snake -1
        score_font = pygame.font.SysFont("comicsansms", 35)
        value = score_font.render("Your Score: " + str(score), True, greencolor)
        dis.blit(value, round(display_width / 3), round(display_height / 5))
        pygame.display.update()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True # The game window is still open
                game_end = False # game has been ended

我没有任何线索......我该怎么办??

【问题讨论】:

    标签: python pygame pygame-surface


    【解决方案1】:

    pygame.Surfac.blit 的第二个参数 (dest) 是一对坐标。包含 2 个组件的元组或包含 2 个元素的列表:

    dis.blit(value, round(display_width / 3), round(display_height / 5))

    dis.blit(value, ( round(display_width / 3), round(display_height / 5) ) )
    

    为了完整起见,必须提到参数也可以是矩形。包含 4 个组件(左、上、宽、高)的元组。

    【讨论】:

    • 非常感谢。因为你的回答,我可以完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 2015-03-22
    • 2020-05-25
    相关资源
    最近更新 更多