In the second block of options, you can switch to the linear gradient mode and set its direction, or you can switch to the radial gradient and set its radius and direction. There are two gradient types – linear gradient and radial gradient. The gradient will smoothly change pixels' alpha levels from full opacity (or original alpha) to the opacity value specified in the options. If you switch to the "Apply Gradient Opacity" mode, the opacity of the pixels changes in a gradient direction. This opacity mode is enabled via the "Apply Solid Opacity" option. By default, all pixels in the PNG get the same alpha channel value (that is, all pixels have the same transparency level). For example, by setting the opacity to 80%, the background will be slightly visible through the PNG by setting the opacity level to 20%, the PNG will be almost transparent and by setting it to 0%, the PNG will be completely transparent (and will maintain the same width and height as the original input PNG). A non-transparent PNG has an opacity level of 100% and a semi-transparent/translucent PNG has an opacity level of less than 100%. You can specify the opacity level in the options on a scale from 0% to 100%. You can make each pixel of a PNG translucent so that the background that lies under the image shines through. (purple_image, PURPLE, purple_image.This browser-based program allows you to change the opacity of any PNG image. (blue_image, BLUE, blue_image.get_rect(), 10) (green_image, GREEN, green_image.get_rect(), 10) (red_image, RED, red_image.get_rect(), 10) # For the 'blue_image' it's the alpha value of the color that's been drawn to each pixel that determines transparency. Remember that the screen is a Surface!īlue_image = pygame.Surface(size, pygame.SRCALPHA) # Contains a flag telling pygame that the Surface is per-pixel alpha Screen.fill(WHITE) # Make the background white. import pygameīLUE = (0, 0, 255, 50) # This color contains an extra integer. Press 2, 3 or 4 multiple times to make them more opaque. Press the keys 1, 2, 3 or 4 to make the images appear. purple_t_colorkey(BLACK)Ĭopy this in an empty file and run it. This can be useful if you don't want the slower performance of a per-pixel Surface. That's why the black rectangle in the middle disappear.Ĭolorkeys and Surface alphas can be combined, but per-pixel alpha cannot. Unlike the other Surfaces, this Surface default color won't be black but transparent. (my_image, BLUE, my_image.get_rect(), 10) The Surface will now draw transparency if the color contains the fourth alpha value. My_image = pygame.Surface(size, pygame.SRCALPHA) # Creates an empty per-pixel alpha Surface. This method also requires the Surface to be created as a per-pixel alpha Surface, and the color arguments needs to contain a fourth alpha integer. This gives you the most freedom and flexibility but is also the slowest method. Makes every pixel in the Surface transparent by a individual alpha value. my_t_alpha(100) # 0 is fully transparent and 255 fully opaque. With this method you can have different alpha values but it will affect the whole Surface. Makes the whole Surface transparent by an alpha value. Colorkeys cannot have different alpha values, it can only make a color not visible. Setting another colorkey will overwrite the previous. My_t_colorkey(BLACK) # Black colors will not be blit.Ī Surface can only have one colorkey. If you have an image with a black rect inside you could set a colorkey to prevent the black color from being blit. Makes a color fully transparent, or more accurately, making a color simply not be blit. There are kinds 3 of transparency supported in pygame: colorkeys, Surface alphas, and per-pixel alphas.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |