views:

153

answers:

5

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

+1  A: 

I don't know what API you're using, so here's a vague answer:

In virtually all cases "clearing" a surface simply blits a coloured quad of the same size as the surface onto it. The colour used is whatever you want your clear colour to be.

If you know how do blit, just blit a white quad of the same size onto the surface.

Pod
A: 

For pygame you can use Surface.fill

gnibbler
Yes I could use it, but here's the tricky part:My surface is being blitted upon another surface, and is using the SRCALPHA flag to support transparency.If I fill the whole surface with a solid color, my whole game board will turn into that color, since this surface is being blitted upon everything....And I don't know how to solve this problem
Eric
@Eric, you should add those requirements to your question
gnibbler
A: 

Fill the surface with fill, then make it transparent with set_alpha

surface.fill
surface.set_alpha(255)
Charles Ma
Ok I tried it without any luck. Still the same problem..
Eric
ah i see what you're trying to do now. No you can't undo a blit on a surface. Follow Kylotan's advice.
Charles Ma
+2  A: 

You can't undo one graphic written over the top of another graphic any more than you can undo one chalk illustration drawn over the top of another chalk illustration on the same board.

What is typically done in graphics is what you'd do with the chalkboard - clear the whole lot, and next time only redraw what you want to keep.

Kylotan
A: 

When I dont care about performance, I use:

mysurface.fill((0,0,0))

Which will draw the specified color (black in this case) across the entire surface. Is that what you meant by "clear"?

Oh, and you need, of course, to "flip" the surface after doing this for it to be visible on the screen.

mizipzor