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

Re: [pygame] Partially Transparent Color-Dynamic Rectangles



Ian Mallett wrote:
Hi,
  I'm making a game where there are status bars overlaying the main screen.  These status bars change in both length and in color according to their length.  e.g., a short bar will be red (warning that you have limited amounts of resource), and a long bar will be green (showing that you have enough of a resource).  This part is not the problem.  What the problem is, is that until now, I've been using pygame.draw.rect() and changing the color and rect. arguments.  Unfortunately, that does not seem to support transparency, which I would now like to have.  Normally, I would make a .png file with the partial transparency and stretch it to fill the bar, but of course, I would need to make a lot of them to cover all possible colors.  Ideas?
Ian
For a simple rectangle you could create a blank surface filled with a color and blit it each time you need to render the bar. For efficiency you could just create a small surface and tile it across the length of the bar. Alternatively you could use numarray to do the blending, although that wouldn't be quite as intuitive.

Regards,

Will McGugan