error, center argument must be a pair of numbers. newbie

Question:

Just trying to draw a circle within a window as a player class, but having some trouble. Can’t get past this error, looked up other posts on the issue but to no avail. Understood that error stems from the need for x,y to be integers and tuple but don’t see how to solve.

import pygame
import os




pygame.init()
window = pygame.display.set_mode((720, 1000))
clock = pygame.time.Clock()
pygame.display.set_caption('Geopocalypse')
bg = pygame.image.load(os.path.join('geobg2.png'))
white= [255, 255, 255]




class Player():
    def __init__(self):
        self.player_surface = window
        self.player_color = white
        self.player_radius = 20
        self.player_width = 0
        self.player_spawn_pos_x = pygame.Vector2(int(window.get_width() / 2))
        self.player_spawn_pos_y = pygame.Vector2(int(window.get_height() / 1.05))
       
    def character(self):
        self.player_character = pygame.draw.circle(self.player_surface, self.player_color, self.player_radius, (self.player_spawn_pos_x, self.player_spawn_pos_y), self.player_width)        
        



player = Player()
run = True  
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    player.character()
    window.fill((0,0,0))
    window.blit(bg, (0,0))  
    pygame.display.update()   




pygame.quit()             
Asked By: Suyosa

||

Answers:

center is the 3rd parameter of draw.circle, not the 4th

You may try passing keyword arguments when you have a long list of them. That should help.

Answered By: Er…

So, the center argument of pygame.draw.circle needs to be a tuple(<int or float>, <int or float>) or list(<int or float>, <int or float>) or Vector2(<int or float>, <int or float>).

In your code, you pass tuple of two Vector2(<int>). I. e. tuple(Vector2<int>, Vector2<int>) instead of Vector2(<int>, <int>) or Vector2(<float>, <float>).

The solution #1 is:

class Player():
def __init__(self):
    self.player_surface = window
    self.player_color = white
    self.player_radius = 20
    self.player_width = 0
    self.player_spawn_pos_x = int(window.get_width() / 2)
    self.player_spawn_pos_y = int(window.get_height() / 1.05)
   
def character(self):
    self.player_character = pygame.draw.circle(self.player_surface, self.player_color, (self.player_spawn_pos_x, self.player_spawn_pos_y), self.player_radius, self.player_width)       

Solution #2:

class Player():
def __init__(self):
    self.player_surface = window
    self.player_color = white
    self.player_radius = 20
    self.player_width = 0
    self.player_spawn_pos = pygame.Vector2(int(window.get_width() / 2), int(window.get_height() / 1.05))
   
def character(self):
    self.player_character = pygame.draw.circle(self.player_surface, self.player_color, self.player_spawn_pos, self.player_radius, self.player_width)       

And in another answer it was correctly noted that you have mixed up the order of arguments.

Answered By: Ivangelion
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.