Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to "clear" a surface?

Is there any way to clear a surface from anything that has been blitted to it?

like image 686
Eric Avatar asked Oct 28 '09 00:10

Eric


1 Answers

If what you want is to make a pygame Surface object "clean", that is erase all images blited to it, to blit new images to it every game loop and keep the peer pixel alpha without creating a new surface, you can fill it, but instead of a solid color, use a transparent color

from pygame import Color, Surface
empty = Color(0,0,0,0) #The last 0 indicates 0 alpha, a transparent color
field = Surface((width, height), flags=SRCALPHA)

#Inside the game loop
field.fill(empty)

*Sorry is my english is bad, still learning

like image 101
Wolfang Torres Avatar answered Sep 29 '22 20:09

Wolfang Torres