PyGame Collision?
问题 How do I find collisions between characters and images within PyGame? I have drawn a player from an image, and have drawn the walls from tiles, so how would I detect these collisions? 回答1: If you use the pygame Rect class to represent the boundaries of your object, you can detect whether two are colliding by using the Rect.colliderect function. For example: import pygame a = pygame.Rect((1, 1), (2, 2)) b = pygame.Rect((0, 0), (2, 2)) c = pygame.Rect((0, 0), (1, 1)) a.colliderect(b) # 1 a