如何在pygame上使用同一个精灵的多个图像?

2024-10-02 04:34:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何使用pygame,并尝试使用同一个精灵的多个图像。我想当我按下键盘上的一个按钮时,精灵的图像会改变。每当我按右箭头键并尝试更改精灵图像时,都会出现错误:

Traceback (most recent call last):
  File "C:\Users\theotheo36\workspace\NomadsPie\main.py", line 55, in <module>
    game.execute()
  File "C:\Users\theotheo36\workspace\NomadsPie\main.py", line 50, in execute
    self.render()
  File "C:\Users\theotheo36\workspace\NomadsPie\main.py", line 32, in render
    self.all.draw(self.screen)
  File "C:\Users\theotheo36\Downloads\WinPython-64bit-3.4.4.3Qt5\python-3.4.4.amd64\lib\site-packages\pygame\sprite.py", line 475, in draw
    self.spritedict[spr] = surface_blit(spr.image, spr.rect)
TypeError: invalid destination position for blit

这是我的代码:

^{pr2}$

Tags: inpy图像selfexecutemainlinepygame
1条回答
网友
1楼 · 发布于 2024-10-02 04:34:46

不要忘记在您的look方法中self.rect=self.image.get_rect后面的括号。不带括号self.rect被分配给函数,而不是返回的矩形。因为它会导致这个矩形的位置错误。在

相关问题 更多 >

    热门问题