hobin
hobin

Reputation: 384

Invalid destination position for blit error

I got this error. This is the full traceback.

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

Here's the code that related the error

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

I don't have any clue... what should I do??

Upvotes: 1

Views: 170

Answers (1)

Rabbid76
Rabbid76

Reputation: 210878

The 2nd argument (dest) of pygame.Surfac.blit has be pair of coordinates. Either a tuple with 2 components or a list with 2 elements:

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

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

For the sake of completeness it has to be mentioned that the argument can also be a rectangle. A tuple with the 4 components (left, top, width, height).

Upvotes: 2

Related Questions