3

I have a program for a random flag generator. I have made a white "background" for a flag, and different symbols etc. which are white. The reason they're white is so I can color it using an RGB value. The problem is, I'm not sure how to do that(if it's even possible), so is it possible to blit an image and give it an RGB value in pygame? For example(this is probably incorrect, but the 2nd tuple in the last 2 blits represents RGB):

surface=pygame.display.set_mode((100,200))
background=pygame.image.load("Background.png")
flagback=pygame.image.load("back.png")
symbol=pygame.image.load("symbol.png")
surface.blit(background,(0,0))
surface.blit(flagback,(0,0),(100,0,0))
surface.blit(symbol,(0,0),(0,100,0))
skrx
  • 19,980
  • 5
  • 34
  • 48
Potensa
  • 33
  • 1
  • 3

1 Answers1

2

You can use the pygame.Surface.fill method to fill a surface with a solid color, e.g.:

background.fill((0, 100, 200))

The line above will fill the whole image, even the transparent pixels.

You can also pass a special_flags argument to use a different blending mode:

background.fill((0, 100, 200), special_flags=pygame.BLEND_MULT)

This one doesn't affect fully transparent pixels.


If you just want to draw some shapes like rects, circles or polygons, use the functions in the pygame.draw (or pygame.gfxdraw) module.

skrx
  • 19,980
  • 5
  • 34
  • 48