0
\$\begingroup\$

While drawing a map for a game in Pygame, I encountered a strange problem. Loading my grass sprite, which is a little over a kilobyte, and placing it, the FPS dropped by half. However, replacing the image with one downloaded from a website that's almost 10 times larger, the FPS returned to normal. Why is my sprite causing such a significant load on the system?

This is my sprite: small grass texture

...and this is the one I downloaded: large grass texture

DMGregory
140k23 gold badges256 silver badges392 bronze badges
asked Aug 3 at 9:55
\$\endgroup\$
8
  • 4
    \$\begingroup\$ In both cases are you comparing loading & placing a single sprite? If you're tiling to cover the screen for instance, it seems like it would take more draw calls when using the smaller sprite. \$\endgroup\$ Commented Aug 3 at 15:22
  • \$\begingroup\$ Possibly related: when I looked at the image info using IrfanView the larger one had its DPI set to 72 x 72 whereas the smaller one didn't have a DPI set. I don't know if that would impact pygame or not, but if it had to rescale it, I would expect that to hurt performance. You could try manually setting the DPI to see if that changes anything. \$\endgroup\$ Commented Aug 3 at 15:27
  • 1
    \$\begingroup\$ Please submit the relevant code snippet where you are drawing the textures. \$\endgroup\$ Commented Aug 4 at 0:08
  • 2
    \$\begingroup\$ Please use Post your answer (should be on the screen below the question) to share your solution rather than answering in the comments. Similarly, edits to your question can be made by clicking Edit link under your question. Comments aren't a good place for answers or edits because their not covered by the site's search / discoverability tools and also more subject to removal. \$\endgroup\$ Commented Aug 4 at 13:46
  • 3
    \$\begingroup\$ Seconding Pikalek's recommendation to include your code as an edit to the question and post your solution as an answer. Not only does this make it easier for other game creators struggling with similar issues to find the solution you shared, it also lets them give you reputation by up-voting your answer. 😁 You may also find this past Q&A about the convert() function useful for reference. \$\endgroup\$ Commented Aug 4 at 16:18

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.