Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading