at Pygame I have a game with a background(at the code the image named:'bg) and an image on that(named:'dice') I'm trying to notice when the player is clicking at the image, but it writing me that the rect of the dice is 0,0(x=0 and y=0), while the image is shown at 740,40.
what should I do?
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()by default would make a pygame.Rect at (0, 0). Try usingdice.get_rect(left=740, top=40).collidepoint(x, y)instead. - Vladimir Shevyakov