python - Is There a Way to Make a Rect Transparent in Pygame? -


is possible make rect transparent in pygame? need because i'm using rects particles game. :p

pygame.draw functions not draw alpha. documentation says:

most of arguments accept color argument rgb triplet. these can accept rgba quadruplet. alpha value written directly surface if contains pixel alphas, draw function not draw transparently. can create second surface , blit screen. blitting alpha blending , color keys. also, can specify alpha @ surface level (faster , less memory) or @ pixel level (slower more precise). can either:

s = pygame.surface((1000,750))  # size of rect s.set_alpha(128)                # alpha level s.fill((255,255,255))           # fills entire surface windowsurface.blit(s, (0,0))    # (0,0) top-left coordinates 

or,

s = pygame.surface((1000,750), pygame.srcalpha)   # per-pixel alpha s.fill((255,255,255,128))                         # notice alpha value in color windowsurface.blit(s, (0,0)) 

keep in mind in first case, else draw s blitted alpha value specify. if you're using draw overlay controls example, might better off using second alternative.

also, consider using pygame.hwsurface create surface hardware-accelerated.

check surface docs @ pygame site, intro.

draw transparent rectangle in pygame

i have had question pygame user before, , method of solving problem.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -