Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

A tutorial that I have followed had me collect and blit all of my sprites with the following lines:

allsprites = pygame.sprite.RenderPlain((l_sprites))
allsprites.draw()

At the moment, this is fine for me, as all of my sprites make use of the same base image. However, I find myself in need of having various sprites animated, some changing, and some going to a basic colored rectangle.

My question is if this batch drawing method is still viable when all of my sprites are in flux. My previous experience has been in straight C with SDL, and normally I would simply roll my own update loop.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The Group class (for which RenderPlain has been a deprecated alias for many years) is more a logical tool than a performance tool. It provides no speed benefit over looping over the sprites yourself. If you are constructing it every frame, it's definitely a net negative.

What you should do instead is replace your l_sprites list of sprites with a group directly. Rather than appending sprites to the list, add them to the group. This lets you use Group.update to update the sprites rather than rolling your own update loop. It also lets sprites remove themselves from the group using Sprite.kill, which is often a more convenient way to remove them.

If you want a performance gain out of using sprite groups, you should turn to RenderUpdates, which returns a list of rectangles appropriate for passing to pygame.display.update.

(If you want good performance, you should give up Pygame's sprite library and turn to OpenGL or one of its Python wrappers instead.)

share|improve this answer
    
I guess this can become a separate question...but OpenGL is better at performance than SDL? I've always been curious but never knew any background on the differences between the two (we did SDL in college) –  espais Aug 5 '11 at 13:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.