减慢pygame中的移动圆

我想通过给它更小的 y 和 x 变化来减慢圆的运动,如下所示:


if event.key == pygame.K_DOWN:

            circleYchange = 0

            circleXchange = 0 

            circleYchange += 0.5

        if event.key == pygame.K_RIGHT:

            circleYchange = 0

            circleXchange = 0 

            circleXchange += 0.5

然后将其添加到circleY和circleX中,并绘制圆:


circleX += circleXchange

circleY += circleYchange

pygame.draw.circle(screen, (0, 0, 0), (circleX, circleY), size)

但它给了我这种错误:


TypeError: integer argument expected, got float

如何减慢运动速度?


ibeautiful
浏览 92回答 1
1回答

森林海

的中心参数pygame.draw.circle()必须是具有 2 个整数组件的元组。您必须将round坐标转换为整数值:pygame.draw.circle(screen, (0, 0, 0), (round(circleX), round(circleY)), size)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python