It sounds like your problem is not in the painting but in your choice of sprites/frames. If you can post an example of what is giving you this "jerky" motion, we might be able to help. What you're probably looking for, however, is a way to interpolate intermediate frames and paint those so that transitions are "smoother." The best way to accomplish that task depends greatly on the subject matter.
Wil
> I mean that I've seen some code where they use
> currentTimeMillis() and assign the value to, let's say
> t, go through the animation calculation, then sleep
> for the frame delay-t so that the delay isn't longer
> if the animation code takes longer.
that isn't particularly useful due to the poor timer resolution of currentTimeMillis().
you'd do better just polling currentTimeMillis() in a tight loop
Check out this article on GameDev.net
http://www.gamedev.net/reference/programming/features/gamemovement/
This question would have been ask by every game developer starting out, luckily nowadays there cool sites site gamedev and flipcode.
The only difference is java doesn't have a precise timer like c++.
Yes its not going to work as precisly, but it works.
My point was that there isn't that much difference between algorithms for this stuff between java and c++, and to use gamedev and other excellent sites. The difference between java's currentTime and the c++ version isn't fundamental.
I have used the same method with some modification in my game, and it works cool.
The basic idea is to record how much time has pass between the current frame and the previous, and use that to scale the distance moved.
one thing i'd definately try is instead of calling repaint(), and then overiding paint is creating a method something like:
updateSprites(){
Graphics g = getGraphics();
//then paint on g
}
then call updateSprites instead of repaint(). This tends to run smoother, i think because calls to repaint() sometimes become cued, so a few paint(Graphics g) calls might end up getting missed.
hope this helps, it did for me when i was doing some Java game coding earlier in the year..