It is not very complicated. You have to remember the previous position and size of the ball. Before you update the screen you have to clear only that part of your viewport. In your case I would guess that you can paint a black rectangle at (x-10, y-10) with size 20x20 instead of clearviewport().
It gets a little bit more complicated if you draw stuff on top of each other. If your ball is drawn on top of some other object like an image you have to replace the black clear-rectangle with a portion of the image that occupies that area.
Xoring pixels is usually much slower than drawing a black rectangle. But that depends on the graphics library, and I am not familiar with this library and have not been able to find its source files. This could easily be measured with a simple test application.
rxlim
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 12
Solved Threads: 8
I have not used this library but it looks like it only supports RGB colors. So if you want to xor pixels without an alpha component I guess you would bitwise-xor the source color with the destination pixel color (the ^ operator) and write it back to the destination pixel using getpixel and setpixel. A normal xor blend operation with only opaque colors would clear pixels where the source pixel and the destination pixel both contain a color (opaque) and the source color would only be drawn to destination pixels without a color (transparent pixels). I am not sure how this is defined for RGB colors. However it is always slower to do operations on pixels rather than just clearing them even when using hardware acceleration. So it is not the preferred way to clear pixels.
rxlim
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 12
Solved Threads: 8