Is it possible to put a picture in a triangle (or any polygon) in pygame?
It is easy to do on a rectangle so is it possible to maybe have a rectangle over a triangle and only show the union of the two shapes?
eg. I only want the part inside the white triangle to show on screen
I tried fitting the picture as rectangle but giving traingle coordinates, It did not work.
If you just want to clip an image, you can use the
pygame.maksmodule.Convert a
pygame.mask.Maskto apygame.Surfacewithpygame.mask.Mask.to_surface. Usesetsurfaceto specify the source image and theunsetcolorargument to specify the transparent background:The mask can be created for example from a triangular polygon:
Minimal example: