减慢pygame中的移动圆圈 [英] Slowing down the moving circle in pygame

查看:87
本文介绍了减慢pygame中的移动圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过像这样给它较小的 y 和 x 变化来减慢圆圈的运动:

I wanted to slow down the movement of the circle by giving it smaller y and x change like this:

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,并绘制圆:

and then adding that to the circleY and circleX, and drawing the circle:

circleX += circleXchange
circleY += circleYchange
pygame.draw.circle(screen, (0, 0, 0), (circleX, circleY), size)

但它给了我这种错误:

TypeError: integer argument expected, got float

我如何减慢运动速度?

推荐答案

pygame.draw.circle() 必须是一个具有 2 个积分组件的元组.你必须round坐标到积分值:

The center argument of pygame.draw.circle() has to be a tuple with 2 integral components. You have to round the coordinate to integral values:

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

这篇关于减慢pygame中的移动圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆