Biki wrote:
It's not recommended. Draw stuff in render() and update the position in update().
how to update its position? :S
EDIT:
Can someone please check this code and see what am I doing wrong?
Code:
public void update(GameContainer arg0, StateBasedGame arg1, int arg2)
throws SlickException {
try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
Input in = arg0.getInput();
int x = in.getMouseX();
int y = in.getMouseY();
boolean c1 = false, c2 = false, c3 = false, c4 = false, c5 = false, c6 = false, c7 = false, c8 = false, c9 = false;
if ((x >= 20 && x <= 149) && (y >= 20 && y <= 134)) {
c1 = true;
} else if ((x >= 172 && x <= 390) && (y >= 30 && y <= 132)) {
c2 = true;
} else if ((x >= 413 && x <= 545) && (y >= 43 && y <= 131)) {
c3 = true;
} else if ((x >= 19 && x <= 142) && (y >= 155 && y <= 430)) {
c4 = true;
} else if ((x >= 166 && x <= 373) && (y >= 155 && y <= 433)) {
c5 = true;
} else if ((x >= 409 && x <= 549) && (y >= 152 && y <= 437)) {
c6 = true;
} else if ((x >= 16 && x <= 140) && (y >= 451 && y <= 576)) {
c7 = true;
} else if ((x >= 163 && x <= 381) && (y >= 456 && y <= 580)) {
c8 = true;
} else if ((x >= 403 && x <= 529) && (y >= 460 && y <= 576)) {
System.out.println("1");
c9 = true;
System.out.println("2");
}
if (c1) {
grid = new GridCube(1);
if ((!grid.isSomethingIn(1)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(20, 20);
}
}
}
if (c2) {
grid = new GridCube(2);
if ((!grid.isSomethingIn(1)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(172, 30);
}
}
}
if (c3) {
grid = new GridCube(3);
if ((!grid.isSomethingIn(3)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(413, 43);
}
}
}
if (c4) {
grid = new GridCube(4);
if ((!grid.isSomethingIn(4)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(19, 155);
}
}
}
if (c5) {
grid = new GridCube(5);
if ((!grid.isSomethingIn(5)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(166, 155);
}
}
}
if (c6) {
grid = new GridCube(6);
if ((!grid.isSomethingIn(6)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(409, 152);
}
}
}
if (c7) {
grid = new GridCube(7);
if ((!grid.isSomethingIn(7)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(16, 451);
}
}
}
if (c8) {
grid = new GridCube(8);
if ((!grid.isSomethingIn(8)) && (!grid.isComsTurn())) {
if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
X.draw(163, 456);
}
}
}
if (c9) {
System.out.println("3");
grid = new GridCube(9);
System.out.println("4");
X.setAlpha(1);
}
}