Reputation: 45
I was wondering how I would undo drawing steps in Python/Pygame. Basically I have made the mouse draw lines, and when I click my undo Rect, I want the screen to revert back to its original state (before mouse was pressed). Here is my code but it does not work well.
copy=screen.copy()
if undoRect.collidepoint(mx,my) and mb[0]==1:
screen.blit(copy,(0,0))
if mb[0]==1 and omb[0]==1:
draw.line(screen,color,(omx,omy),(mx,my),5)
can someone who knows what I mean please give me ideas on how to make an undo last drawing button?
Thank you.
Ps. I am fairly new to pygame/python so please go a little slowly.
Upvotes: 1
Views: 1423
Reputation: 2087
You just need to save the frames when the user interacts with the application.
For example in a demo paint application I wrote with opengl I used a list with 20 elements max and I was updating it when the user started a new action.
If user clicks to the screen, save the current frame to the list. If user stop clicking save the new frame. Then, when you need to go back you just have to take the last element of your list and draw it to the screen.
Upvotes: 2