Selectively reset the color of the surface after blitting PyGame

I have two green surfaces

s1 = Surface((100, 100))
s2 = Surface((100, 100))

s1.fill((0, 255, 0))
s2.fill((0, 255, 0))

Then i blit them on main surface with beautiful background

screen.blit(image.load("ocean.png").convert_alpha(), (0, 0))
screen.blit(s1, (0, 100))
screen.blit(s2, (200, 100))

Result:

Result

Question: How can i selectively reset the color of one of the green surfaces after i have already blitted this surface on another surface? As if this surface never existed.

Desired result:

Desired result

Note:

PyGame methods set_alpha and set_colorkey don’t change anything. In addition, they will not allow to reset the surface selectively.

screen.set_alpha(0) # no changes

Or

sreen.set_colorkey((0, 255, 0)) # no changes

>Solution :

How can i selectively reset the color of one of the green surfaces…?

This is impossible

You cannot "reset" the color to a previous state. Each pixel of a surface knows only one color, the current color. However, you can blit a part of the original background on the rectangular area:

background = image.load("ocean.png").convert_alpha()
screen.blit(background, (200, 100), area=pygame.Rect(200, 100, 100, 100))

Leave a Reply