在PyGame中继承Sprite类并使用组是否会使游戏更快?
它有助于游戏的性能吗?还是我应该闪闪发光的图像?在Pygame官方纪录片中,它说:“它(pygame.sprite.sprite
)是可见游戏对象的基类。”和“ IT(pygame.sprite.group
)是Sprite对象的简单容器。”现在,例如子弹,我有两个选择:
1。继承类并在触发某些东西时将其添加到组中
或
2。不要继承并在某些触发器时手动创建列表,然后将其添加到列表中。
我对一个小组的想法是,它融合了小组中的所有内容。那么每个类中的此和screen.blit()
之间有什么区别?
如果没有区别,则pygame.surface.groupsingle
确实没有任何用处。所以我不确定该使用
(u+1f937)
Does it help the game's performance? Or should I just blit the images? In the pygame official documentary, it said "It (pygame.sprite.Sprite
) is the base class for visible game objects." and "It (pygame.sprite.Group
) is a simple container for Sprite objects." Now for example a bullet, I have two options:
1. inherit the class and add it to a group when something triggers
or
2. don't inherit and create a list manually and add it to the list when something triggers.
What I think of a group, is it blits everything in the group. Then what's the difference between this and screen.blit()
in each class?
If there is no difference, then pygame.surface.GroupSingle
really doesn't have any use. So I'm not sure what should I use
(U+1F937)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pygame.sprite.sprite
模块使代码更短并且更容易理解并为您提供功能,例如pygame.sprite.spritecollide
,pygame.sprite.sprite.sprite.layeredupdates
等。基础代码可高度优化,可与SDL 2一起使用。 Pygame是基于的。但是,背后没有魔术。 pygame的一部分是用C/C ++写的(请参阅 github -pygame)。因此,在场景后面没有python for-lor-lor-lor-the Code> .blit for code> blit 。用组绘制精灵比用python -loop和
blit
的python绘制更有效。无论如何,如果您知道自己在做什么,则可以在没有
pygame.sprite.sprite
模块的情况下编写有效的代码。pygame.surface.GroupSingle
并非没有用。它可以像其他任何组一样使用,可以与pygame.sprite.spritecollide
等一起使用。The
pygame.sprite
module make the code shorter and easier to understand and offer you features likepygame.sprite.spritecollide
,pygame.sprite.LayeredUpdates
etc. The underlying code is highly optimized for use with the SDL 2 on which the pygame is based. However, there is no magic boost behind it. Parts of pygame are written in C/C++ (see GitHub - pygame). So there is no python for-loop behind the scenes that calls
.blit
for each sprite. Drawing the sprites with a group is more efficient than drawing with a pythonfor
-loop andblit
. Anyway, if you know what you are doing, you can write effective code without thepygame.sprite
module.pygame.surface.GroupSingle
is not useless. It can be used like any other group and can be used withpygame.sprite.spritecollide
etc.