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

Re: [pygame] Rotation Performance



Hello.

You don't need to worry about creating threads for this app.

On Wed, Jan 20, 2010 at 7:08 PM, Bram Cymet <bcymet@xxxxxxxxx> wrote:
Hi All,

I did some profiling of my pygame application and I found that it was
spending a lot of time doing rotation operations. Basically I have some
balls on the screen that are represented by gifs with transparent
backgrounds and I want to make them spin.

I use the following code:
 
This is because .rotate() creates a new surface, an expensive operation. [similar to if you had a image.load() every game loop. ]

What you can do is rotate the image, and save it as a single image containing all rotations like a spritesheet. Or one image per rotation. Doesn't matter. [You can automate this in pygame, or other apps.]

However, the solution could be to use OpenGL to render in 2D.
For every 'sprite' You create a mesh/rect, and set it's texture to the ball sprite. At render you rotate the square to the angle.

If you haven't used openGL, you are able to create a window with Pygame and PyOpenGL.
There's a couple OpenGL recipies http://www.pygame.org/wiki/CookBook , http://pyopengl.sourceforge.net/documentation/index.html

--
Jake