Python ';TypeError:应为整数参数,获得浮点值';
我正在用python做一个游戏,我有一个错误 应为整数参数,得到浮点值 ,我不明白为什么。给出错误的行是:Python ';TypeError:应为整数参数,获得浮点值';,python,python-3.x,pygame,Python,Python 3.x,Pygame,我正在用python做一个游戏,我有一个错误 应为整数参数,得到浮点值 ,我不明白为什么。给出错误的行是: pygame.draw.circle(屏幕,(128,128,128), (自位置[0]-1,自位置[1]-1),自大小+1) 第三个参数必须是整数坐标(tuple(x,y)),但除法(/)的结果是浮点值 使用或从浮点值转换为整数值: pygame.draw.circle(屏幕,(128,128,128), (int(自位置[0]-1)、int(自位置[1]-1))、自大小+1) 或者
pygame.draw.circle(屏幕,(128,128,128),
(自位置[0]-1,自位置[1]-1),自大小+1)
第三个参数必须是整数坐标(tuple(x,y)
),但除法(/
)的结果是浮点值
使用或从浮点值转换为整数值:
pygame.draw.circle(屏幕,(128,128,128),
(int(自位置[0]-1)、int(自位置[1]-1))、自大小+1)
或者在计算自身位置时,使用整数除法(/
)代替浮点除法(/
):
self.location=(屏幕大小[0]//2,屏幕大小[1]//2)
另见 谢谢你,你帮了我这么多!这个问题在Android上不会发生。
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