Python 如何获取动态圆的rect()
我试图在draw方法中获取圆的矩形,但Pygame每次在Alien实例上调用get_rect()方法时都会出错。我想要一个用于碰撞检测的动态圆曲面,因为我的代码生成不同大小的随机圆。如果您有任何帮助,我们将不胜感激Python 如何获取动态圆的rect(),python,pygame,pygame-surface,Python,Pygame,Pygame Surface,我试图在draw方法中获取圆的矩形,但Pygame每次在Alien实例上调用get_rect()方法时都会出错。我想要一个用于碰撞检测的动态圆曲面,因为我的代码生成不同大小的随机圆。如果您有任何帮助,我们将不胜感激 class Alien(): def __init__(self, etc): self.x = random.randrange(0,600) self.y and self.size are also random variables d
class Alien():
def __init__(self, etc):
self.x = random.randrange(0,600)
self.y and self.size are also random variables
def draw(self, screen, colour):
pygame.draw.circle(screen, colour, (self.x, self.y), self.size)
我想从draw方法得到这个圆的rect,但它没有rect方法。我在网上查过了,我发现你可以使用pygame.surface,但我不知道如何使用它为我的圆生成曲面,因为当我生成20个不同的外星人圆对象时,模块的所有绘图函数返回一个矩形,表示已更改像素的边界区域
更新您的draw()
方法
def draw(self, screen, colour):
return pygame.draw.circle(screen, colour, (self.x, self.y), self.size)
返回一个
pygame.Rect
object,你可以用它来检测碰撞。我真的不明白你的问题。我将坚持使用典型的最小示例代码,并描述发生了什么以及您期望的结果。