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

Re: [pygame] creating a sprite image in code



Here's an example that creates a white circle with diameter "size" with a transparent background:

image = pygame.Surface((size, size), 0, 8)
key_color = (0, 0, 0)
image.fill(key_color)
image.set_colorkey(key_color)
pygame.draw.ellipse(image, (255, 255, 255), image.get_rect())

Obviously you can draw whatever you like in your image surface.

hth,

-Casey

On May 1, 2007, at 12:08 PM, Rodney Brown wrote:

I've seen examples on how to load sprites or sprite pages from a .bmp file, but I haven't seen an example of making a simple sprite in code.

Does anybody know of an example where the sprite image is created in the code itself, instead of loading a graphics file? For what I'm working on at the moment I only need say a 3x3 sprite, which would be a waist to have to load it from a .bmp file.

Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.