how to restart applet without closing it
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...
Code :
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?
Re: how to restart applet without closing it
Use a variable to tell the method not to double the time.
Re: how to restart applet without closing it
i just did some debuging and the result are shocking.
turn out that value of timer isnt change and my animation speed(dx) isnt changing too. and yet my animation are speeding up.
should i submit all my code so you can run and see the problem?
Re: how to restart applet without closing it
Is the speed up caused by an additional timer being started?