Pages

duminică, 3 martie 2013

PyGame : 5 simple rules help you to programming in pygame.

Some rules when you want to use pygame:
1. Use hardware rendering :
>>> import pygame 
>>> show=pygame.display.set_mode((400,400), pygame.HWSURFACE | pygame.DOUBLEBUF)
2. Use function convert and load BMP file.
>>> im=pygame.image.load("9.bmp").convert()
... also you got the error:
>>> im2=pygame.image.load("9.png")
Traceback (most recent call last):
  File "", line 1, in 
pygame.error: File is not a Windows BMP file
3. Don't use reserved words in your variables, like display, time ...
4. Be advice about low performance. For example, a simple 2D game no needs to use threads. Also the bad configuration of game, wrong sprites, group classes used or using unoptimized images heavily and you will have a low performance.
5. Use the profiler to test how much time your game spend on event handling, computing, and drawing. Don't guess what is wrong?