使用Rect函数参数的Pygame类型错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Rect函数参数的Pygame类型错误相关的知识,希望对你有一定的参考价值。

我收到了这个错误

File "main.py", line 48, in update
    self.rect = self.rect.move((self.dirx, self.diry))
TypeError: argument must contain two numbers

self是一个具有rect属性的sprite对象。在我的游戏中,我试图通过使用以下方式移动这些精灵:

self.rect = self.rect.move((self.dirx, self.diry))

dirx和乳制品只是在1到3之间(表示速度)。我问过多个同行,但没人能给我反馈。

编辑所以发生的事情是污垢和污垢变得太大而不能用另一种方法来考虑

答案

问题是我在其他地方增加dirx和脏太多,我认为它们太大了,它会自动转换为很长的。

另一答案

尝试将两个数字作为两个参数传递,而不是官方文档中显示的元组:

move(self.dirx, self.diry)

https://www.pygame.org/docs/ref/rect.html#pygame.Rect.move

另一答案

你将它作为一个元组返回,你需要返回数字。尝试:self.rect = self.rect.move(self.dirx, self.diry)

以上是关于使用Rect函数参数的Pygame类型错误的主要内容,如果未能解决你的问题,请参考以下文章

Pygame Rect区域位置(图解)

Python碰撞使用pygame检测图像(图像类型:png)

Pygame错误:self.spritedict [spr] = surface_blit(spr.image,spr.rect)

为什么pygame rect不在正确的位置?

如何移动pygame rect?

pygame:屏蔽非图像类型的表面