Basicly, I\'m making a game which to update the players position, it uses this thread:
@Override
public void run() {
while(true) {
System.out.pri
You didn't post the code to updatePos
. But at a minimum, you need to make that method, as well as keyPressed
(and anything else that uses x
and/or y
) synchronized
.
Alternatively you can make both x
and y
volatile
, but then x
and y
could get updated out of lockstep.
But without any memory synchronisation, changes from one thread are not guaranteed to be observable from another thread.