在 Pygame 中获得平滑的对角线移动

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

我正在使用 pygame 开发这个贴花创建器。你基本上有一堆控制角度、半径、偏移量等的滑块。滑块以整数递增。

随着我增加距中心的偏移量,您会注意到这些点并没有沿着完美的直线路径移动。

这是我用来绘制点的代码:

def drawAADot(surf, center, radius, color):
    gfx.aacircle(surf, center[0], center[1], radius, color)
    gfx.filled_circle(surf, center[0], center[1], radius, color)

此代码用于沿圆形路径分布点:

for i in range(divisions+1):
    i *= (angle/(divisions))
    move_vec = pygame.math.Vector2(center)
    move_vec.from_polar((radius + DotOffset, i+90-counter_angle))
    pos = center[0] + round(move_vec.x), center[1] + round(move_vec.y)
    drawAADot(screen, pos, DotRadius, (255,255,255))

我已经搜索并阅读了有关浮动精度移动的问题,因为对象的坐标需要是整数。我不明白的是,一旦职位四舍五入,在这种情况下它是否真的很重要。我可以看到 45 度角可以平滑运行,只要你增加一个像素横向和向上。但是让我们说 15 度怎么样?

它不一定是 AutoCad 精度,我知道这些限制,我只是想知道我没有忽略某些东西或者这已经很好了。

提前谢谢你。

python pygame drawing
1个回答
-1
投票

必须将整数传递给绘图例程吗?

或者您可以删除

round
电话,即更改

pos = center[0] + round(move_vec.x), center[1] + round(move_vec.y)

pos = center[0] + move_vec.x, center[1] + move_vec.y

好的,我看到你被锁定在整数位置显示

那样的话,你就被锁定在这个问题上了。唯一能减少这种尴尬的方法就是步子大一些,这样就不太引人注意了。

Downvoting 不会在 PyGame 中创建浮点图形坐标功能!要是生活就这么简单就好了。 8-)

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