在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