The problem is that the width
variable is not set until the size()
method is executed in setup()
Change your code to
int buttonSize = 260;
int buttonY = 500;
int button2X;
and in setup
void setup(){
size(480, 320); // use your own width and height
button2X = width/2-(buttonSize/2);
// rest of your setup code
}