英文:
What is the Group.lostsprites attribute for in pygame?
问题
在pygame中,groups具有一个lostsprites
属性。这个属性用于什么目的?
在代码中首次定义的链接:pygame/src_py/sprite.py
似乎这是一种内部的东西,因为我无法找到关于它用途的任何文档:
- 在pygame网站上搜索只返回1个结果(未解释其用途):lostsprite - Search Results
- 我还尝试在Google上搜索,但什么都找不到。
英文:
In pygame, groups have a lostsprites
attribute. What is this for?
Link to where its first defined in the code: pygame/src_py/sprite.py
It seems to be some sort of internal thing as I was unable to find any documentation on its purpose:
- Searching on the pygame website yields 1 result (which doesn't explain its purpose):
lostsprite - Search Results - I also tried searching on google but I couldn't find anything
答案1
得分: 1
lostsprites
是一个内部属性,用于跟踪组操作影响的所有矩形区域。该属性在基类 AbstractGroup
中实现,其确切行为取决于组的类型(Group
、RenderUpdates
、OrderedUpdates
等)。
draw
方法返回在绘制过程中发生变化的所有区域。这不仅包括精灵之前的区域和精灵的新区域,还包括已移除精灵的区域(例如 pygame.sprite.kill
)。这就是 lostsprites
的作用所在。当从组中移除精灵时,精灵所在的矩形区域被添加到 lostsprites
中,稍后在 draw
方法中使用这些信息。
英文:
lostsprites
is an internal attribute that helps to keep track of all rectangular areas affected by the operations of the group. The attribute is implemented in the base class AbstractGroup
and the exact behavior depends on the type of the group (Group
, RenderUpdates
, OrderedUpdates
, ...).
The draw
method returns all the areas that were changed during drawing. This includes not only the areas that the sprites were before and the new areas of the sprites, but also the areas of the removed sprites (e.g. pygame.sprite.kill
). This is where lostsprites
comes into play. When a sprite is removed from the group, the rectangular area where the sprite was is added to lostsprites
and later this information is used in draw
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论