我一直在写一个测试功能学习鼠标“点击”动作上pygame.rect如何将导致效应初探。
至今:
def test():
pygame.init()
screen = pygame.display.set_mode((770,430))
pygame.mouse.set_visible(1)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250,250,250))
screen.blit(background, (0,0))
pygame.display.flip()
## set-up screen in these lines above ##
button = pygame.image.load('Pictures/cards/stand.png').convert_alpha()
screen.blit(button,(300,200))
pygame.display.flip()
## does button need to be 'pygame.sprite.Sprite for this? ##
## I use 'get_rect() ##
button = button.get_rect()
## loop to check for mouse action and its position ##
while True:
for event in pygame.event.get():
if event.type == pygame.mouse.get_pressed():
## if mouse is pressed get position of cursor ##
pos = pygame.mouse.get_pos()
## check if cursor is on button ##
if button.collidepoint(pos):
## exit ##
return
我也碰到过对谷歌的网页,人们正在使用或建议使用pygame.sprite.Sprite
类的图片,我想,这就是我的问题是从。 我检查了pygames文档并没有方法太大的凝聚力,恕我直言。 我明明简单的东西,但是,我想get_rect
将使在pygames图像能够检查是否按下时鼠标的位置已经结束了吗?
编辑:我想我需要调用pygame.sprite.Sprite
方法,使图像/ rects互动?