I'm making a platformer in which I make the player jump by, every 30ms, adding a small amount of force upwards. I thought I'd use multi-threading, as I've done a little bit of it before and it seemed simple enough. Anyway, I tried this:
public void jump() {
new Runnable() {
public void run() {
for (int i = 0; i <= jumpForce; i++) {
velocity.y++;
System.out.println("Adding force");
try {
wait(30);
} catch (InterruptedException e) {}
}
}
}.run();
}
Now, what I thought this would do is every loop from 0 to jumpForce (in this case 50), it adds 1 onto the y velocity variable then waits 30ms, but what actually happens is I get an error called:
java.lang.IllegalMonitorStateException
and I have no idea what this means so can someone tell me what I'm doing wrong?