I'm currently working on a space exploration game in 2D top view. I have quite a few planets and since the map span is much greater than the display I end up with a lot of planet sprites lying outside the display area. At the moment I assume Pygame will not actually blit the sprite if they are not located in the display (as I understand it blitting and drawing to a surface slows things quite a lot) is that true ? Or would I need to add a condition to check if the sprite is located within the display prior to the blit call ? The reason I'm asking is that the way my game works is that each time a planet is discovered 2 new ones are created ... which means that the game can get quite big, and potentially very slow.
Thank you
No, it won't blit the images. Pygame will simply ignore it if you're trying to blit something that's outside of the screen. It shouldn't slow down your program unless there's a huge amounts of objects, since it'll take a fraction of time for pygame to determine that the image is outside of the screen. This isn't a huge deal though.
Realized my answer lacked proof (which is bad, mkay...), so I ran some test to prove my point. I tested 3 conditions: blitting to the screen, blitting outside the screen, and doing nothing. The number of seconds they took are insignificant because they're based on my computer's performance (a 5 year old laptop), so look for the factors between them instead; they should be similar for everyone.
5,000 blits
500,000 blits
50,000,000 blits
As you can see, blitting outside the screen takes more time than not blitting, but it doesn't take nearly as much time as actually blitting to the screen. Blitting outside the screen is barely a cost.
For further reference, here's the test I created: