当我在窗口中间放一个圆圈时,我得到一个错误

问题描述 投票:1回答:1

这是代码注释:代码中有一些我还没有实现的东西。我正在使用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

期望整数参数,浮点数

python pygame
1个回答
1
投票

在pygame中,任何引用像素的参数都应该是int类型,而不是float。您可以通过更改HWHH来解决此问题:

HW = W // 2
HH = H // 2

/运算符总是返回一个浮点数。如果两个操作数都是//s,int运算符会给你一个int

© www.soinside.com 2019 - 2024. All rights reserved.