如何在 pygame 中显示平滑的加载栏?
How can I display a smooth loading bar in pygame?
我目前正在 pygame 开发一款游戏。
我想创建一个加载 window 与软件 GIMP 一样的加载栏,但我真的不知道如何优化它,...根本
所以这是我的代码的一部分,显然,它运行得不是很好。
你能帮帮我吗?
...
screen = pygame.display.set_mode((640, 480), pygame.NOFRAME)
where = (120,360)
While in progress = true:
If 1/a < 0.25
screen.blit(Load0, where)
If 1/a < 0.50
screen.blit(Load1,where)
#... ( it's the same for <0.75 and = 1 )
pygame.display.update()
game()
但它使中继加载栏错误...
你能帮我让它更优化更流畅吗?
PS : 我有 350 个元素要加载
简化事情,用2个矩形画一个条形。
创建一个绘制条形的函数。该函数绘制一个细长的外部矩形和填充的内部矩形。内部矩形的长度取决于进度。 progress
是 [0, 1] 范围内的值。如果为 0,则不绘制内柱。如果为 1,则内柱完整:
def DrawBar(pos, size, borderC, barC, progress):
pygame.draw.rect(screen, borderC, (*pos, *size), 1)
innerPos = (pos[0]+3, pos[1]+3)
innerSize = ((size[0]-6) * progress, size[1]-6)
pygame.draw.rect(screen, barC, (*innerPos, *innerSize))
定义条形的位置和颜色参数:
barPos = (120, 360)
barSize = (200, 20)
borderColor = (0, 0, 0)
barColor = (0, 128, 0)
定义最大项目数:
max_a = 350
当你绘制条形图时,当前进度为a/max_a
:
DrawBar(barPos, barSize, borderColor, barColor, a/max_a)
我目前正在 pygame 开发一款游戏。 我想创建一个加载 window 与软件 GIMP 一样的加载栏,但我真的不知道如何优化它,...根本
所以这是我的代码的一部分,显然,它运行得不是很好。 你能帮帮我吗?
...
screen = pygame.display.set_mode((640, 480), pygame.NOFRAME)
where = (120,360)
While in progress = true:
If 1/a < 0.25
screen.blit(Load0, where)
If 1/a < 0.50
screen.blit(Load1,where)
#... ( it's the same for <0.75 and = 1 )
pygame.display.update()
game()
但它使中继加载栏错误...
你能帮我让它更优化更流畅吗?
PS : 我有 350 个元素要加载
简化事情,用2个矩形画一个条形。
创建一个绘制条形的函数。该函数绘制一个细长的外部矩形和填充的内部矩形。内部矩形的长度取决于进度。 progress
是 [0, 1] 范围内的值。如果为 0,则不绘制内柱。如果为 1,则内柱完整:
def DrawBar(pos, size, borderC, barC, progress):
pygame.draw.rect(screen, borderC, (*pos, *size), 1)
innerPos = (pos[0]+3, pos[1]+3)
innerSize = ((size[0]-6) * progress, size[1]-6)
pygame.draw.rect(screen, barC, (*innerPos, *innerSize))
定义条形的位置和颜色参数:
barPos = (120, 360)
barSize = (200, 20)
borderColor = (0, 0, 0)
barColor = (0, 128, 0)
定义最大项目数:
max_a = 350
当你绘制条形图时,当前进度为a/max_a
:
DrawBar(barPos, barSize, borderColor, barColor, a/max_a)