[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Pygame tutorial



Hi,

just been trying out this pong tutorial and noticed that it ran very 
poorly on my machine. Had a quick look at the code and noticed this:

    screen.blit(background, ball.rect )
    screen.blit(background, player1.rect )
    screen.blit(background, player2.rect )

this code renders the ENTIRE background image (clipped to the screen) 
at the locations of the ball and players. 

Thats three times.

It was slowing to a crawl when the ball and the bats approached the top 
of the screen.

Should look like this:

    screen.blit(background, ball.rect, ball.rect)
    screen.blit(background, player1.rect, player1.rect)
    screen.blit(background, player2.rect, player2.rect)

which copies a small rectangular region from the background image
to the screen, erasing the old ball/player position.

This seems to be an amusing demonstration of what happens when 
people are let-loose on massively over-the-top hardware. Goodness 
knows what you people must be using not to have noticed this :-)

I test on a P166Mhz-MMX, (that's 166Mhz not 1.6Ghz). I find that it 
keeps me frosty.

On a more positive note, the journalistic quality of the tutorial 
itself is good, you just need to sort out the code,

good-luck and best regards,
John.
PS the attached patch for tompong-0.4 fixes this and another 
performance related issue: font creation.

Attachment: tompong-0.4-patch.zip
Description: Zip compressed data