O'Reilly logo

Instant Pygame for Python Game Development How-to by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing sprites (Intermediate)

Sprite is a term from computer graphics meaning a two-dimensional visible object, that has been optimized for rendering. Pygame offers the Sprite class that deals with sprites. It can draw sprites on a Surface object. It also has collision functions. For complex games, we can group sprites together for easy management. Sprites are not thread safe, so you should take care when using multiple threads.

How to do it...

We will redo the animation demo, but this time with sprites and using Rect objects, which represent rectangles. A Rect object has left, top, width, and height attributes. We will use these and other attributes throughout the example. Also we will let the avatar spin when the mouse button is clicked. However, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required