rect.center 会改变 rect 属性吗?
您好,
我在 pygame 中从事的项目似乎遇到了一些麻烦。 对于我使用的一个对象:
image.get_rect()
并将其分配给:
self.rect
我了解 get_rect 函数的默认坐标给出的值为 (0,0)。 结果,我使用:
self.rect.center = (320,240)
将精灵大致放置在屏幕中间。但是,稍后在 hitTest 函数中,我想调用:
self.rect.colliderect(other_rect)
我收到错误:“tuple”对象没有赋值“colliderect”。
发生这种情况是因为 self.rect.center 赋值改变了 self.rect 的属性吗?
Greetings,
It seems I am having a bit of trouble with a project I'm working on in pygame.
For one of my objects i used:
image.get_rect()
and assigned it to:
self.rect
I understand the default coordinates for the get_rect function gives a value of (0,0).
As a result, I used:
self.rect.center = (320,240)
To roughly place the sprite in the middle of the screen. However, later on in a hitTest function, I want to call:
self.rect.colliderect(other_rect)
I get an error: 'tuple' object has no assignment 'colliderect'.
Does this happen because the self.rect.center assignment change the properties of self.rect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
元组类型是不可变的。也就是说,一旦设置,就无法更改。
我假设 Colliderect 正在尝试修改一个元组。
使用列表代替该元组。
The tuple type is immutable. That is, once set, you cannot change it.
I assume that colliderect is trying to modify a tuple.
Use a list in place of that tuple.