blit 错误的无效目标位置 [英] Invalid destination position for blit error
本文介绍了blit 错误的无效目标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到了这个错误.这是完整的回溯.
<块引用>回溯(最近一次调用最后一次):文件C:/Users/hobin/PycharmProjects/codeitPython/Snake_game.py",第 103 行,在 <module> 中.蛇游戏()文件C:/Users/hobin/PycharmProjects/codeitPython/Snake_game.py",第 52 行,在蛇游戏中dis.blit(value, round(display_width/3), round(display_height/5))类型错误:blit 的目标位置无效
这是与错误相关的代码
虽然不是 game_over:而 game_end == True:#用于显示分数分数 = Length_of_snake -1score_font = pygame.font.SysFont("comicsansms", 35)value = score_font.render("你的分数:" + str(score), True, greencolor)dis.blit(value, round(display_width/3), round(display_height/5))pygame.display.update()对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:game_over = True # 游戏窗口仍然打开game_end = False # 游戏已经结束
我不知道……我该怎么办??
解决方案
pygame.Surfac.blit
是一对坐标.包含 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 个组件(左、上、宽、高)的元组.
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??
解决方案
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).
这篇关于blit 错误的无效目标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文