中心参数必须是一对数字

center argument must be a pair of numbers

我正在努力让脚本为将要创建的形状生成一个随机的 x 位置。

我是 python 的新手,所以我不知道如何解决这个问题。

代码部分:(在 pygame 游戏循环内)

class falling_object():
    def __init__(self):
        pass

    def create():
        global random_x
        random_x = random.randint(10, 470)
        random_size = random.randint(20, 40)
        pygame.draw.circle(screen, (255, 255, 0), random_x, falling_y, random_size, random_size) # error is here at the random_x and random_size part, falling_y is a variable equal to 0

调用函数的地方:

obj1 = falling_object()
falling_object.create()

pygame.draw.circle 的中心参数需要是具有 x 和 y 坐标的元组:

pygame.draw.circle(screen, (255, 255, 0), random_x, falling_y, random_size, random_size)

pygame.draw.circle(screen, (255, 255, 0), (random_x, falling_y), random_size) 

在构造函数中创建球体的坐标并在方法中绘制球体:

class falling_object():
    def __init__(self):
        self.x = random.randint(10, 470)
        self.y = falling_y
        self.size = random.randint(20, 40)

    def create(self):
        self.y = falling_y
        pygame.draw.circle(screen, (255, 255, 0), (self.x, self.y), self.size)

在应用程序循环之前构建球体,但在循环中绘制:

obj1 = falling_object()

# [...]

while running:

    # [...]  

    obj1.create()