这是代码 注意:代码中有一些我尚未实现的东西。 我正在使用pygame制作滚动游戏,并试图降低基础知识。
import pygame
class Player:
def __init__(self, x, y, size):
self.x = x
self.y = y
self.size = size
self.jumping = False
self.jump_offset = 0
WHITE = (255, 255, 255)
BLACK = 0
W = 1280
H = 720
HW = W / 2
HH = H / 2
win = pygame.display.set_mode((W, H))
CLOCK = pygame.time.Clock()
FPS = 30
pygame.display.set_caption('if the shoe fits wear it')
p = Player(HW, HH, 30)
jump_height = 50
running = True
while running:
pygame.draw.circle(win, WHITE, ((p.x, p.y)), p.size, BLACK)#problem
pygame.display.update()
CLOCK.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
这是错误
Traceback (most recent call last):
File "C:/pygame/jump.py", line 34, in <module>
pygame.draw.circle(win, WHITE, ((p.x, p.y)), p.size, BLACK)
TypeError: integer argument expected, got float
Process finished with exit code 1
预期为整数参数,为浮点数
答案 0 :(得分:1)
在pygame中,任何引用像素的参数都应为int
类型,而不是float
类型。您可以通过更改HW
和HH
来解决此问题:
HW = W // 2
HH = H // 2
/
运算符始终返回浮点数。如果两个操作数均为//
,则int
运算符将为您提供int
。