呼叫按钮仅滴答一秒钟,无法显示文字?

巴兹

我正在做游戏,我想当我在车库里时,如果我购买更多速度并且已经达到最高速度,则会弹出一个文本,提示“达到最高速度!”。但是,当我单击该按钮并达到最大速度时,它不会停留,而是在1滴答声后消失。由于按钮的工作方式,我无法弄清楚如何使其停留更长时间。任何帮助表示赞赏。这是按钮的代码:

            elif event.type == pygame.MOUSEBUTTONDOWN:
                # 1 is the left mouse button, 2 is middle, 3 is right.
                if event.button == 1:
                    # `event.pos` is the mouse position.
                    if button2.collidepoint(event.pos):
                        print('we been clicked')
                        current_time = time.strftime("%S")
                        # Increment the number
                        if player.vel < 20:
                            if player.coins >= 50:
                                player.vel += 5
                                player.coins -= 50
                                print('speed =' + str(player.vel))
                                player.vel1 = player.vel
                                player.grassvel = player.vel // 2
                                player.save()
                            else:
                                print("ur poor")
                        else:
                            MaxSpeedReached()

这是它调用的函数的代码:

def MaxSpeedReached():
    display_crash_text = False
    print("Max speed reached")
    if display_crash_text == False:
        start_time = time.strftime("%S")
        display_crash_text = True
    maxspeedtext = pygame.font.Font("freesansbold.ttf", 20)
    maxspedd, maxspeedr = text_objects("Max Speed  Reached!", maxspeedtext, BLACK)
    maxspeedr.center = ((205, 270))
    print(current_time, start_time)
    if display_crash_text == True:
        win.blit(maxspedd, maxspeedr)
        if int(start_time) - int(current_time) < 3:
            display_crash_text = False
            print("yo we checking the time difference")
金斯利

显然,您会看到此消息,因为MaxSpeedReached()调用时会绘制一次消息,但是到达此函数的唯一可能路径是pygame.MOUSEBUTTONDOWN事件。

每当出现最大速度的条件时,您都需要在主循环中绘制消息。

MAX_VELOCITY = 20

maxspeedtext = pygame.font.Font("freesansbold.ttf", 20)
maxspedd, maxspeedr = text_objects("Max Speed  Reached!", maxspeedtext, BLACK)
maxspeedr.center = ((205, 270))

[ ... ]

# Main loop
while not finished:

    [...]

    if ( player.vel >= MAX_VELOCITY ):
        win.blit( maxspedd, maxspeedr )

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

骨干视图仅渲染一秒钟

来自分类Dev

按钮仅绘制图像一秒钟

来自分类Dev

如何显示图像一秒钟?SWIFTUI

来自分类Dev

显示登录页面一秒钟

来自分类Dev

一秒钟的JavaScript真的是一秒钟吗?

来自分类Dev

一秒钟的JavaScript真的是一秒钟吗?

来自分类Dev

“不要保留活动”-恢复应用程序后,该片段仅显示一秒钟

来自分类Dev

“不保留活动”-恢复应用程序后,该片段仅显示一秒钟

来自分类Dev

SwiftUi-隐藏“后退”按钮和导航栏(显示时间不到一秒钟)

来自分类Dev

使用X11窗口的R脚本仅打开一秒钟

来自分类Dev

使用X11窗口的R脚本仅打开一秒钟

来自分类Dev

Javascript验证-错误消息仅闪烁一秒钟

来自分类Dev

每隔一秒钟从Observable获取数据,使用“开始”和“停止”按钮

来自分类Dev

一秒钟内查询数量很高。

来自分类Dev

一秒钟后边界半径消失

来自分类Dev

一秒钟后悬停消失

来自分类Dev

需要循环睡眠一秒钟的时间

来自分类Dev

一秒钟后边界半径消失

来自分类Dev

花费一秒钟锁定屏幕

来自分类Dev

录制一秒钟的视频Swift?

来自分类Dev

在TextView上显示时,CountDownTimer跳过一秒钟

来自分类Dev

nmap会在本地主机上显示随机打开的端口一秒钟

来自分类Dev

下拉菜单显示的时间不会超过一秒钟。

来自分类Dev

Android,Glide显示错误的图像大约一秒钟

来自分类Dev

为什么我的嵌套gridview只显示一秒钟?

来自分类Dev

如何使打印语句的输出延迟一秒钟显示?

来自分类Dev

如何在Java中仅一秒钟更改文本框的背景颜色?

来自分类Dev

tmux状态栏消息仅持续一秒钟:我可以扩展它吗?

来自分类Dev

软件在任务栏中仅闪烁一秒钟。如何找出它是什么软件?

Related 相关文章

热门标签

归档