We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How do I create an undo button?
Page Index Toggle Pages: 1
How do I create an undo button?? (Read 668 times)
How do I create an undo button??
Jan 24th, 2008, 11:09pm
 
Hi,
I want to create an undo button in processing but i don´t know how. I need to return one object to its last position... i don't know if you understand me... Thanks!!
Re: How do I create an undo button??
Reply #1 - Jan 25th, 2008, 10:16am
 
You can create a class with an array which saves the last positions like this:

Code:

class MyClass(){
int[][] lastPositions;

MyClass(){
lastPosition=new int[10][2];
for(int i=0, i<10; i++){
lastPosition[i][0]=0;
lastPosition[i][1]=0;
}
}

void update(int x, int y){
for(int i=8, i<0; i--){
lastPosition[i]=lastPosition[i+];
}
lastPosition[9][0]=x;
lastPosition[9][1]=y;
}

void getBack(){
for(int i=1, i<10; i++){
lastPosition[i]=lastPosition[i-];
}
}

int[] getPos(){
return lastPosition[9];
}
}
Page Index Toggle Pages: 1