pygame仅在满足某些条件时显示图片

发布于 2025-01-30 02:24:58 字数 727 浏览 3 评论 0原文

我正在使用Pygame制作游戏,只有在放在光标上,我希望出现一张图片。这是我所做的:

while True:

        clock.tick(FPS)

        mx, my = pygame.mouse.get_pos()

        
        darktower_rect = pygame.Rect(x, y, DARK_TOWER.get_width(), DARK_TOWER.get_height())
        if darktower_rect.collidepoint((mx,my)):
            WIN.blit(DARK_TOWERT, (x, y))
            if click:
                main()
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()

            if event.type==pygame.MOUSEBUTTONDOWN:
                if event.button==1:
                    click=True
        
        pygame.display.update()

这起作用了,但是问题是,blit将图片保留在那里,我希望图片在鼠标不再在上面之后消失。

I am making a game in pygame and I want a picture to appear, only if the cursor is on it. Here is what I did:

while True:

        clock.tick(FPS)

        mx, my = pygame.mouse.get_pos()

        
        darktower_rect = pygame.Rect(x, y, DARK_TOWER.get_width(), DARK_TOWER.get_height())
        if darktower_rect.collidepoint((mx,my)):
            WIN.blit(DARK_TOWERT, (x, y))
            if click:
                main()
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()

            if event.type==pygame.MOUSEBUTTONDOWN:
                if event.button==1:
                    click=True
        
        pygame.display.update()

This works, but the problem is, that blit keeps the picture there, and I want the picture to disappear, after the mouse is no longer on it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2025-02-06 02:24:58

如果您闪烁(绘制)到win表面,它将一直留在那里,直到在其上绘制某物或清除表面为止。

在更新添加到代码之后清除显示器后清除显示。

pygame.display.update() win.fill(0)

之后, 您指定0而不是RGB值,显示将填充黑色。

If you blit (draw) to the WIN surface it will stay there until something is drawn over it, or the surface is cleared.

To clear the display after updating append to your code right after pygame.display.update()

WIN.fill(0)

This will fill the window surface with a color, if you specify 0 instead of an rgb value, the display will fill with black.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文