在pygame我有一个背景游戏(在代码图像命名:'bg)和一个图像(命名:'骰子') 我是试图注意玩家何时点击图像,但是它向我写道,骰子的矩形是0,0(x = 0和y = 0),而图像显示在740,40。pygame不认识我的形象
我该怎么办?
bg = pygame.image.load("temptry.gif")
dice=pygame.image.load("dicee.gif")
screen.blit(bg, (0, 0))
bg.blit(dice,(740,40))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
# Set the x, y postions of the mouse click
x, y = event.pos
print dice.get_rect()
if dice.get_rect().collidepoint(x, y):
print "omg"
screen.blit(bg, (0, 0))
bg.blit(dice,(740,40))
pygame.display.update()
'dice.get_rect()'默认会在(0,0)处产生一个pygame.Rect。尝试使用'dice.get_rect(left = 740,top = 40).collidepoint(x,y)'代替。 –
omg yess非常感谢你!!!!!而已! – roni280