bei Pygame Ich habe ein Spiel mit einem Hintergrund (im Code das Bild namens: 'bg) und ein Bild auf dem (mit dem Namen:' Würfel ') Ich bin versuchen zu bemerken, wenn der Spieler auf das Bild klickt, aber es schreibt mir, dass die Rect der Würfel 0,0 (x = 0 und y = 0) ist, während das Bild bei 740,40 gezeigt wird.pygame erkennt nicht die richtige rect meines Bildes
was soll ich tun?
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()' standardmäßig eine pygame.Rect an machen würde (0, 0). Verwenden Sie stattdessen 'dice.get_rect (left = 740, top = 40) .collidepoint (x, y)'. –
omg yess danke dir so viel !!!!! das ist es! – roni280