fixing jumpy animation
in
Programming Questions
•
1 year ago
I'm writing a very simple sketch that moves a square around based on keyboard input.
Keyboard directions just add some acceleration in their direction up to a certain speed cap (the acceleration in each direction can only be increased once each draw loop). There is also a constant drag acceleration which will slow the square when input stops.
The problem that I'm having is that the square will appear to jump in the animation at higher speeds.
I know why this is: the square gets moved at its speed each time the draw loop executes. So at higher speeds it will jump around because its speed starts moving it a noticeable distance from its start location per draw loop.
I tried a couple things - I brought up the frame rate, which I thought might allow for a finer grained rendering of the movement, but that didn't fix the issue. I also started rendering offscreen (via PGraphics) and only drawing to the canvas once per draw loop. That also didn't fix the issue.
My question is what is there a technique that I can use to smooth out the animation so that it doesn't appear to jump but still moves at the same speed? I want to fill in the animation from its start point to where it will end up at the end of the draw iteration.
Or maybe just point out the flaw in my movement algorithm. This is my first foray into animation so I'm pretty green.
Here is a link to my code on github:
Thanks for your help!
1