pygame仅在满足某些条件时显示图片
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您闪烁(绘制)到
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.