ok so i kind of know how to restart but the problem is that when ever i restart my animation get faster and faster.
so i have main.java and alot of other objects. so one class for player one for player one for background etc...
public class main exteds JApplet actionlistener
{
public void init()
{
//create window stuff
}
public void start()
{
player_class = new player1();
//create all classes
timer_class = new Timer(10, this);
timer_class.start();
}
public void actionPerformed(ActionEvent e)
{
//all collsion stuff go in here
repaint();
}
public void paint(graphics g)
{
//paint here
}
public void stop(){} //i dont use this method. well i dont know how to
public void mousePressed(MouseEvent e)
{
//restart button here
if(...)
{
if(...)
{
//if user hit restart button
//i am calling start() method again so it restart
start(); //--------------this is how i am restarting
}
}
}
}
i think what is happing is that when i call start(); method at bottom it double my timer.
so 1st my timer is 10 than restart now its 20 ... and so on. that why my animation get faster and faster?
any idea how can i fix this issue. or is there a better logic to restart?