在照例程做pygame外星人小游戏时遇到精灵组碰撞检测的问题,不是很明白。以下是pygame.sprite.groupcollide()的官方文档
Find all sprites that collide between two groups.
groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict
This will find collisions between all the Sprites in two groups. Collision is determined by comparing the Sprite.rect attribute of each Sprite or by using the collided function if it is not None.
Every Sprite inside group1 is added to the return dictionary. The value for each item is the list of Sprites in group2 that intersect.
If either dokill arg

本文介绍了pygame库中用于检测精灵组之间碰撞的函数pygame.sprite.groupcollide。该函数通过比较每个Sprite的rect属性或使用回调函数来判断碰撞。如果dokill参数为True,相撞的精灵将从各自组中移除。当未提供collided函数时,所有精灵必须有rect属性以计算碰撞。通过示例,解释了groupcollide返回值的三种情况:无碰撞返回空字典,碰撞则返回包含子弹和外星人键值对的字典,便于实现游戏逻辑如增加得分。
最低0.47元/天 解锁文章
227

被折叠的 条评论
为什么被折叠?



