javafx - Using a Timeline to display animation when a button is pressed. -


i making small game user can make character walk around screen , make preform attack motion. of images create animation saved in arrays. game loop using animationtimer , working way want far user being able control character , character being abel move around screen. however, problem having animationtimer runs fast when want display character attacking , runs through array of attack images fast able see ending image. tried set when space bar pressed attack start timeline , timeline through array of attack images @ slower rate. want timeline run 15 time(size of attack array), display images in attack array, return game. not sure if using timeline correctly because seems timeline not consistently running same number of times every time called. question how able solve problem of being able display , array of images @ slower rate still able use original game loop? arrays same size attackdown.length size of arrays. method attack() gets called main class every time space bar pressed. controlled animationtimer.

  public void attack(graphicscontext gc){      timeline timeline = new timeline(new keyframe(             duration.millis(2500),             e ->attackdisplay(gc)));      timeline.setcyclecount(attackdown.length);      timeline.play();  }    private void attackdisplay(graphicscontext gc){      system.out.println("in attack" + " a: " + a);      if(a < (attackdown.length-1))         a++;      else         = 0;      if(facing == 'd'){         gc.fillrect(0,0,width,height);         gc.drawimage(attackdown[a],xloc,yloc);      }else if(facing == 'u'){         gc.fillrect(0,0,width,height);         gc.drawimage(attackup[a],xloc,yloc);      }else if(facing == 'l'){         gc.fillrect(0,0,width,height);         gc.drawimage(attackleft[a],xloc,yloc);      }else if(facing == 'r'){         gc.fillrect(0,0,width,height);         gc.drawimage(attackright[a],xloc,yloc);      }  }  


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -