[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Should I use Sprites and Groups ?



Can you please share the code, so we can look into it?

Op 10 dec. 2015 15:20 schreef "Yann Thorimbert" <Yann.Thorimbert@xxxxxxxx>:

Hi,


I'm currently looking into a "big" minigame that I wrote a few years ago. At this time, I dit not try to use Sprites and Groups objects, and so the code I'm talking about does not use them. Now that I want toÂcontinue the development of this game,ÂI wonder how much the code would gain in clarity and performances ifÂI usedÂSprites.


Basically,ÂIÂhaveÂa few (~10-30)Âimages to draw on the screen, each one beeing approximately a rect of 20-100 pixels width/height. Since not all these images must be drawn each frame, and since most of them don't overlap, what I did is a loop that check for each one if it needs to be drawn (for user input reasons, for instance), and if so, the image is redrawn and then a call to pygame.display.update(image.get_rect()) is done.


However, some tests I have made show that, instead of updating each image'rect, a single call to pygame.display.flip() each frame sometimes does the job better, in term of performances, depending on the sizes and number of images to draw.


I'm not sure to really understand how Sprite and Groups works behind the scene : from what I described of my code, do you think it could significantly improve performances if I use them ? Would it handle better than me theÂupdates of the screen surface ?


Cheers,


Yann