Reputation:
Is there any way of defining an invisible Color in pygame, so that calling it on screen.fill(invisibleColor,pygame.mouse.get_pos())
wouldn't cover the drawings behind it?
Upvotes: 1
Views: 384
Reputation: 1531
There are three different methods for transparency in Python; looking at The documentation for fill it looks like you will need to pass the special flags into the last parameter to support whichever transparency method you are using.
What I found useful was to use the convert_alpha()
function Documented here rather than convert
on my surfaces; I discovered that in my case the transparency wasn't working because I was using regular convert
.
ADDITIONAL:
I'm not 100% clear on what you are trying to achieve, but it occurs to me that you may mean you want only a rectangle under the mouse to be visible and you mean to use transparency to do that. If that is the case there are a couple of problems:
If this is what you are trying to achieve, you may do better to just render a smaller surface (the bit that's under the mouse) and draw that to the screen over your solid background.
If you really do want to draw a solid rectangle with a hole under the mouse you will need to draw four rectangles like this (sorry for the ascii art):
+------------------+
| 1 |
+------+---+-------+
| 2 | m | 3 |
+------+---+-------+
| 4 |
+------------------+
That way the bit of the screen under the mouse (marked m
in the 'diagram') will not be covered by your solid colour, but the rectangles 1,2,3&4 will all appear to be one solid rectangle (with a hole under the mouse).
Hope this helps refine the answer to suit your needs.
Upvotes: 2