2
votes

I'm doing a game in python and I have one error

integer argument expected, got float

, and I'm not understanding why. The line that give me error is:

pygame.draw.circle(screen, (128, 128, 128), 
    (self.location[0]-1, self.location[1]-1), self.size+1)
class Player(object):
    def __init__(self, name, colour):
        self.name = name
        self.colour = colour
        self.level = 1
        self.feed = 0
        self.size = 2
        self.speed = 6
        self.location = (SCREEN_SIZE[0]/2, SCREEN_SIZE[1]/2)
        self.destination = self.location
        self.stopDis = 5    #Stopping distance

    def render(self, screen):
        pygame.draw.circle(screen, (128, 128, 128),
            (self.location[0]-1, self.location[1]-1), self.size+1)  #Error here
        pygame.draw.circle(screen, self.colour, self.location, self.size)   #Draw circle
1
This problem does not occur on Android. - Jean-Pierre Schnyder

1 Answers

3
votes

The 3rd parameter to pygame.draw.circle has to be a integral coordinate (tuple (x, y)), but the result of a division (/) is a floationg point value.

Use int or round to cast self.location from floating point values to integral values:

pygame.draw.circle(screen, (128, 128, 128), 
    (int(self.location[0]-1), int(self.location[1]-1)), self.size+1)

Or do a integral division (//) instead of the floating point division (/), when you calculate self.location:

self.location = (SCREEN_SIZE[0] // 2, SCREEN_SIZE[1] // 2)

See also Numeric Types.