在PyGame中继承Sprite类并使用组是否会使游戏更快?

发布于 2025-02-05 00:25:44 字数 409 浏览 1 评论 0原文

它有助于游戏的性能吗?还是我应该闪闪发光的图像?在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2025-02-12 00:25:44

pygame.sprite.sprite 模块使代码更短并且更容易理解并为您提供功能,例如pygame.sprite.spritecollidepygame.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 like pygame.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 python for-loop and blit. Anyway, if you know what you are doing, you can write effective code without the pygame.sprite module.
pygame.surface.GroupSingle is not useless. It can be used like any other group and can be used with pygame.sprite.spritecollide etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文