I am attempting to clear a surface before using blit() to another surface. Before I was clearing path_surface by making it opaque, using blit() to the movement_surface, and resetting it's opacity (more on that here).
The issue I'm now having is that it is overwriting everything on the movement_surface, so instead I need to just clear the path_surface before I blit it to movement_surface. In an attemp to do this I'm creating a clear_surface and trying to use it to reset path_surface. It does not have any effect.
Code:
def undraw_movement(self):
empty = pg.Color(0,0,0,0)
clear_surface = pg.Surface(self.path_surface.get_size(), pg.SRCALPHA)
clear_surface.set_alpha(150)
clear_surface.fill(empty)
clear_surface.set_alpha(None)
self.path_surface.blit(clear_surface, (0,0))
self.movement_surface.blit(self.path_surface, (0,0))
There is no easy way to "undo" a blit in pygame, and unfortunately without the full code or an example of what you want to happen it is not possible to find a simpler way. If you only want to remove the latest move you could keep a copy of the surface with [surface].copy() before making any changes to it and return to that when needed. If you really need to be able to remove any move the only thing I can think of would be creating a new surface for every move that is made and assigning it a position, then when you need to remove the move you can just take that surface out of the list and reblit everything.
Without the full code or knowing what you are trying to achieve on a larger scale I can't really offer any help other than this. If you are struggling preformancewise from drawing there are other solutions, such as using colorkey instead of SRCALPHA if you don't need a transparency value or only drawing 60 times per second that are much simpler to implement and cleaner solutions in general.