Check out example codes for "animationtimer javafx". It will help you in understanding the concepts better.

Code Example 1

static int speed x ;
// prefered speed to start with = 5;

new AnimationTimer(){
  long lastTick = 0;
  @Override
  public void handle(long now){
    if(lastTick == 0 ){
      frame();
      lastTick = now ;
      return;
    }
    if(now - lastTick > 1000000000 / speed){
      frame();
      lastTick = now;
    }
    
    }
  }.start();

Learn ReactJs, React Native from akashmittal.com