• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Intermittent Pauses in Sprite Animation when Using Keybindings in JavaFX

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everyone,

I am trying to animate movement of a rectangular sprite across the screen using keyboard controls, but I notice subtle pauses in the animation initially. There are typically one to three pauses, jerks or jitters. Then the rest of the time, the animation is generally smooth.

Here is a gif showing the movement.

Gyfcat Link

In the below code, I use keybindings to set boolean flags for the direction keys. Then in an animation timer, I check the flag, set the sprite's velocity and set the sprite's layout property. I restrict movement to one axis at a time. I do diagonal movement by alternating movement in each axis.

Please try this code.




In this post (How to get smooth animation with KeyPress event in javaFX?), the answer was varying the sprite speed with the animation timer's time argument, but even when I vary the speed using the timer, there is still pausing.

In this post (In JavaFX how do I move a sprite across the screen?), the answer moves the sprite by the position properties instead of the layout properties, but that did not resolve this pausing.

In addition, I have tried using setOnKeyPressed and setOnKeyReleased, but there was no effect on the problem.

I considered that there may be video card or memory problems with the computer, so I tried this code on two computers and the problem exists on both computers. Both computers ran the code in Windows 10 and the Eclipse IDE.

Similarly, when I run the code here, (Key Combinations), I also see these kinds of pauses in the animation, so I am worried that it might not just be my code.

Please help me resolve these subtle pauses in animating a rectangular sprite using keybindings.

Thank you very much for taking a look at my problem.

P.S. I have also posted this question at stackexchange (Pauses in Sprite Animation when Using Keybindings in JavaFX).
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for informing us of your crosspost.

I ran your code on an very average Windows 10 system with a basic graphics card.  I experienced only the slightest hesitations now and then, barely noticeable but there.
 
Tomo Sagatchi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for running it.  I am at a bit of a loss about the cause, especially since it seems to perform better after a little time.
 
You may have just won ten million dollars! Or, maybe a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic