I probably do it wrong, so please be kind. I am developing a Java game and I am at the stage of testing movement / animation of characters.
The face can move up and down the grid. The class into which the grid is inserted is the gamePanel class. The buttons are in the gameControlPanel class.
I have a button that spawns a person in a grid. Then I have a button to move my face up and down.
When the move up button is pressed, it calls the move up method from the person class. (At the moment I am testing only one βpersonβ at a time). The following code is in this method ...
int move = 10; while(move!=0) { setTopLeftPoint(new Point((int)getTopLeftPoint().getX(), (int)getTopLeftPoint().getY() - 3)); try { Thread.sleep(300); } catch (InterruptedException e) {
The problem is that I cannot name the repaint method for the gamePanel class from the Person class. To get around this, I created a timer in the gamePanel class, which replicates every 20 ms.
When I press the up button after the person is generated, the button remains pressed until the while loop cycles are completed, and then the circle image is displayed in the grid square above.
I will try to answer any questions regarding this.
java multithreading timer animation swing
Relequestual Apr 21 '09 at 13:59 2009-04-21 13:59
source share