Pygame FirstGame (6) – Saving framerate with Group

Spread the love

See how to same frame rate grouping all sprites and showing them all at once on the screen, rather than showing them individually. With Group of the class sprite of the module pygame (that I called pg) you can group more sprites and thed update the group, instead of a single sprite. Watch the video to see how the framerate gain a lot of benefits from this and how I avoided grouping the sprites every frame.

I made this change:

after I created the group that I called g

I called this function above that takes all the sprites in the dictionary, that is the following

So that, now, I got all my sprite in g.

Then I just update g in the while loop

The while loop calls the update_screen every frame

So that the udpate screen clears the screen and calls show_sprites()

That draws the group and update the animation image (prepare to show in the next frame (or 180 frames that I used to slow down the image progression to make it go slower).

The whole code


Pygame's Platform Game

Other Pygame's posts