Hi all. I'm probably doing this wrong, so please be nice. I'm developing a java game, and I'm at the stage of testing character movement / animation.
The "person" can move up down left and right on a grid. The class the grid is drawn in the gamePanel class. The buttons are in the gameControlPanel class.
I have a button which spawns a person on the grid. I then have a button to move the person up down left and right.
When the move up button is pressed, it calls the move up method from the person person. (As I'm only allowing one person at current for testing) In that method is the following code...
int move = 10;
while(move!=0)
{
setTopLeftPoint(new Point((int)getTopLeftPoint().getX(),
(int)getTopLeftPoint().getY() - 3));
try
{
Thread.sleep(300);
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
move-=1;
}
The problem is, I cant seem to call the repaint method for the gamePanel class from within the Person class. To get round this, I created a time in the gamePanel class which repaints every 20ms.
When I press the up button after the person is sawned, the button remains pressed down until the cycles of the while loop has been completed, and then the circle representation of the person is displayed in the grid square above.
I will try to answer any questions regarding this. Please help.
Thanks in advance
Rel