Increasing speed of Timer in Java -


i'm making game java , i'm using timers animations , game controls. i'm having trouble choosing right way increase speed of timer. game supposed faster , faster game progresses, , i'm finding there many ways increase speed of objects, i'm not sure 1 efficient use.

for example, let's int xpos variable increments xposition of object.

timer timer = new timer(100, new actionlistener()  //01 {                                                  //02     public void actionperformed(actionevent e)     //03     {                                              //04         xpos++;                                    //05         repaint();                                 //06     }                                              //07 }                                                  //08                                                    //09 timer.start();                                     //10 

to increase speed of this, increase incrementation of xpos on line 5 xpos+=2.

i increase speed decreasing millisecond parameter timer to: timer timer = new timer(50, new actionlistener() on line 1.

or add second timer same task double speed of timer. basically, this:

mover mover = new mover(); timer timer = new timer(100, mover);         timer timer2 = new timer(100, mover); timer.start(); timer2.start();  class mover implements actionlistener {                                                       public void actionperformed(actionevent e)          {                                                       xpos++;                                             repaint();                                      }                                               }    

which 1 think effective? or should combine these techniques? replies.

  • keep timer beat steady, invariant.
  • store logical position , velocity doubles or point2d.double.
  • don't rely on accuracy of timer interval.
  • calculate change in position based on velocity , change in system time.

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -