Smooth Animation

Anyone know how to get really smoth animation? I'd like some tips so that I won't have jerky animation. Maybe some faster image drawing methods than drawImage? I've done some games before but this has been a problem.
[226 byte] By [JTeen] at [2007-9-27 16:49:19]
# 1
here is a tutorial I used to help smoothen my animations,using the infamous techniques of double buffering andupdate() overloading: http://www.programming.de/java_tutorial/j_tutor09.htmlhope this helps.
carmichaelbaby at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 2
Use BufferStragegy to automatically handle double buffering. Works especially well in full screen exclusive mode.
rgeimer at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 3
I'm already using double buffering. I've checked my code for the word new. I'm using an applet. Is there any alternate way of putting images on the screen besides paint? Also, I don't have any problems with flickering, it's just a little jerky.
JTeen at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 4

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

wilh at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 5
Sometimes it skips frames, and the fps isn't always constant. Some people use currentTimeMillis(), but I've heard it's unreliable. Is it? Also, is there any faster way of drawing images than drawImage()?
JTeen at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 6
Thread.sleep is supposed to be more accurate than currentTimeMillis for waiting a required period of time.
YATArchivist at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 7
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.
JTeen at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 8

> 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

Abuse at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 9
How far do you move your image each frame? If it's more than a few pixels, your animation will be jerky. Try moving fewer pixels per frame, then lower the amount of time it spends sleeping between frames.
Jetset_Willy at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 10
sleeping between frames is wasteful
Abuse at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 11

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++.

harleyrana at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 12
> The only difference is java doesn't have a precise> timer like c++.which is a kind of a fundamental difference :/without a precise timer, the ideal animation technique cannot be applied.
Abuse at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 13

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.

harleyrana at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...
# 14

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..

gusgorman at 2007-7-6 1:07:15 > top of Java-index,Other Topics,Java Game Development...