问题描述
我有一个需要按特定顺序绘制的精灵组,这样它的精灵就应该重叠.
I've got a sprite group which needs to be drawn in a certain order so its sprites overlap as they should.
但是,即使使用运算符模块函数 (sorted(self.sprites, key=attrgetter('y','x')) 对组进行排序时,顺序也是错误的.
However even when sorting the group using operator module function (sorted(self.sprites, key=attrgetter('y','x')) the order is wrong.
我该如何解决这种行为?
How can I fix this behaviour?
推荐答案
直截了当,你可以't:
Group 不以任何顺序保存精灵,所以绘制顺序是随意.
改用 OrderedUpdates 组:
这个类派生自 pygame.sprite.RenderUpdates
- Group 类跟踪脏更新.它保持精灵的顺序添加到组进行渲染.这使得添加和删除来自 Group 的 Sprite 比普通 Groups 慢一点.
或者,您可以在不同的组中保留不同层"的精灵,保持组的正确顺序.
Alternatively, you can keep different 'layers' of sprites in different groups, keeping the order of groups correct.
这篇关于pygame:使用 sprite.RenderPlain 绘制精灵组的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!