//Pylons
int xCoord[];
int yCoord[];
int numSquare;
boolean firstPaint;
public void init() {
//Images Call
pylon = getImage(getDocumentBase(), "image/pylon.png");
numClicks = 0;
//pylons
xCoord = new int[100];
yCoord = new int[100];
numSquare = 0;
}
public void paint(Graphics g) {
if (numClicks == 0) {
drawUI(g);
//probeDraw(g,2);
}
if (numSquare == 1) {
for (int k = 0; k < numSquare; k++) {
g.drawImage(pylon, xCoord[k], yCoord[k], this);
}
Minerals -= 100;
popMax += 9;
}
}
public boolean mouseDown(Event e, int x, int y) {
if (numClicks == 10) {//Title screen
numClicks++;
repaint();
}
if (numSquare == 0) {
xCoord[numSquare] = x;
yCoord[numSquare] = y;
numSquare++;
repaint();
}
return true;
}
When i do this instead of just minusing 100 it will put it at like -300 and it wil add the popMax to like 36 instead of 10. Some times it will do it correct and sometimes it won’t its really annoying
you’re updating class-level variables in paint(…), a method which is called every time the ui component needs repainting. I’m not surprised it’s annoying.
You need to split the logic that handles click actions out of the paint method – and use the paint method to render just the CURRENT STATE of your component.
Edit: Further to your comments, and without knowing the structure of your application, I imagine you would need something like this: