pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
777 stars 123 forks source link

How to load a super large image? #2768

Closed feiyuhuahuo closed 3 months ago

feiyuhuahuo commented 3 months ago

I want to develop the following function: The game window just show part of the whole world map, and the window can be dragged to anywhere as the player want. image The world map is quite large, thus I was thinking use a super large image, e.g. 40000*40000 pixel. I tried pygame.image.load() but it takes too long time to finish loading and occupies too large memory. How to deal with this? Is my method right that use a super large image as the entire scene map?

robertpfeiffer commented 3 months ago

Your method would occupy roughly 4.5 GiB of RAM at 24 bits-per-pixel RGB. There is no single fool-proof way around this. You could try using run-length encoding (RLEACCEL), but I don't think it could fix your issue, unless your image is already so sparse that another approach would work even better. There are many ways to represent a large level in memory, but this bug tracker is not the place to discuss spatial data structures or game design.