1

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
upcast
  • 59
  • 4
  • When you blit your are overwriting what's on the screen with something new. The only way to revert that is to redraw the background and left square. – B Remmelzwaal Feb 01 '23 at 18:37

1 Answers1

1

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

This is impossible

Each object in the scene is drawn to the pygame.Surface object associated with the display. screen is a pygame.Surface object and blit is short for block image transfer.
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))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174