Pygameで私はバックグラウンドを持つゲームを持っています(画像の名前は 'bg)とその画像(名前:' dice ') 私はプレーヤーが画像をクリックしているときに気付いたが、サイコロの矩形は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()'はpygame.Rectを(0、0)にします。代わりに 'dice.get_rect(left = 740、top = 40).collidepoint(x、y)'を使ってみてください。 –
ええ、ありがとう、あまりにも!!!!!それでおしまい! – roni280