简体   繁体   English

Pygame - 更有效地从spritesheet blit sprite,或blit invidual sprite到他们自己的表面?

[英]Pygame - More efficient to blit a sprite from spritesheet, or blit invidual sprites to their own surfaces?

Using pygame, would it be more efficient to: 使用pygame,它会更有效:

  1. Blit a single sprite from a portion of a spritesheet each frame 每帧从spritesheet的一部分blit一个sprite
  2. At startup, blit each sprite from a spritesheet to their own Surfaces, then blit those Surfaces 在启动时,将每个sprite从spritesheet blit到他们自己的Surfaces,然后blit那些Surfaces

Is there any performance differences between the two? 这两者之间是否有任何性能差异? Would it take more draw calls to use the first method, versus individual Surfaces at startup (ie does doing this at startup store copies of those pixels in ram/vram)? 是否需要更多的绘制调用来使用第一种方法,而不是在启动时使用单个Surfaces(即在启动时执行此操作会在ram / vram中存储这些像素的副本)?

Thanks 谢谢

It would be faster to blit the images into a surface, then blit those surfaces. 将图像blit到表面会更快,然后将这些表面blit。

However it would consume more memory, since you'll need to keep those surfaces somewhere in memory. 但是它会占用更多内存,因为你需要将这些表面保留在内存中的某个位置。

Why? 为什么?

When you go to blit the image from your spritesheet, you'll end up subsurfing/clipping the spritesheet surface, which will mean you'll need to generate another surface on the spot. 当您从spritesheet中进行blit图像处理时,您将最终对spritesheet表面进行冲刺/剪裁,这意味着您需要在现场生成另一个表面。 However, this process won't take long. 但是,这个过程不会花费很长时间。

The performance benefit most likely isn't worth it, so I'd recommend just go with whichever method you're most comfortable with. 性能优势最有可能是不值得的,所以我建议你选择最适合的方法。 If you're concerned about performance, check out the builtin CProfile python module. 如果您担心性能,请查看内置的CProfile python模块。

VRAM never comes into this equation. VRAM永远不会进入这个等式。 pygame.Surface is derived from SDL_Surface from the SDL library for the C programming language. pygame.Surface派生自SDL库的SDL_Surface ,用于C编程语言。 SDL_Surface is primarily targeted toward software rendering , which means the surface pixels are stored in standard RAM. SDL_Surface主要针对软件渲染 ,这意味着表面像素存储在标准RAM中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM