python - 加载栏进行时如何在背景中显示图像?
问题描述
所以我做了一个加载栏并设法让它成功工作。但是,我想在进度条正在进行时在背景中显示图像,并且每当我尝试时我的动作都会化为乌有。
我试图添加一个新行,它会不断地“blit”图像。screen.blit(loadingimg) 但它最终给出了这个错误:
DS.blit(loadingimg)
TypeError: function missing required argument 'dest' (pos 2)
smallfont = pygame.font.SysFont("comicsansms",25)
DS = pygame.display.set_mode((W, H))
def text_objects(text, color, size):
if size == "small":
textSurface = smallfont.render(text, True, color)
return textSurface, textSurface.get_rect()
def loading(progress):
if progress < 100:
text = smallfont.render("Loading: " + str(int(progress)) + "%", True, green)
else:
text = smallfont.render("Loading: " + str(100) + "%", True, green)
DS.blit(text, [453, 273])
def message_to_screen(msh, color, y_displace = 0, size = "small"):
textSurf, textRect = text_objects(msg, color, size)
textRect.center = HW, HH + y_displace
DS.blit(textSurf, textRect)
while (progress/2) < 100:
event_handler()
DS.fill(WHITE)
DS.blit(loadingimg)
time_count = (random.randint(1,1))
increase = random.randint(1,20)
progress += increase
pygame.draw.rect(DS, green, [423, 223, 204, 49])
pygame.draw.rect(DS, BLACK, [424, 224, 202, 47])
if (progress/2) > 100:
pygame.draw.rect(DS, green, [425, 225, 200, 45])
else:
pygame.draw.rect(DS, green, [425, 225, progress, 45])
loading(progress/2)
pygame.display.flip()
time.sleep(time_count)
应该发生的是出现一个加载条,并且在加载进度条时,背景中有一个图像。进度条达到 100% 后,它会移动到下一件事,但在这种情况下,我只希望它们在达到 100% 后都消失
我的实际输出就是这个错误:
DS.blit(loadingimg)
TypeError: function missing required argument 'dest' (pos 2)
解决方案
请参阅blit()的文档。它还需要定位 -blit(image, (x,y))
或blit(image, rect)
DS.blit(loadingimg, (0, 0))
blit()
不仅用于显示背景,还用于显示玩家的图像、敌人的图像——它们可以显示在屏幕上的任何位置。
推荐阅读
- arrays - 如何接收消息队列中的消息以列出
- minikube - minikube 内核:hpet1:丢失 319 个 rtc 中断
- tfs - 使用 Visual Studio 2017 获取/结帐失败
- excel - 找到 FindNext 匹配项时复制相邻单元格时遇到问题
- android - 我怎样才能把它变成一个 lambda?
- karate - 从空手道请求中的参数值中删除引号
- python-3.x - 在 python 中解析 html 文件中的项目(类似于 JSON 模块的功能)
- c# - Linq to Objects 将在源上迭代多少次?
- sql - oracle 中的 row_number() 函数
- javascript - Javascript - 链接 2 个(或更多)承诺数组