1,精靈與精靈
pygame.sprite.collide_rect(first, second)
2,精靈與組
#第一個參數是精靈,
#第二個參數是精靈組,
#第三個參數爲True,則碰撞檢測後,組中所有碰撞的精靈被刪除
#返回 組中被碰撞的精靈
collide_list = pygame.sprite.spritecollide(sprite,group,False)
3,組與組
#前兩個參數都是組
#後兩個參數,代表發生碰撞時,是否刪除精靈
#該函數返回一個字典
#第一個組中的每一個精靈都會添加到字典中
#第二組中與之碰撞的精靈會添加到字典相應的條目中
hit_list = pygame.sprite.groupcollide(group1,group2,True,False)
注:這裏的組都是 pygame.sprite.Group() 創建的組
歡迎大家留言討論~