Animation smoothness question

I have a blue square, I want to move it right by increasing its X-coardinate by a value Speed pixels.

like this:X = X+Speed

The problem is if I want to have a high speed like 10 pixels the square appears to jump to the right. It doesn't move smoothly.

if I use a low speed like 1 pixel the square moves smoothly but smoothly. I want it to move smoothly and fast at a speed of 10 pixels without appearing to jump.

Any suggestions?

[462 byte] By [Thargana] at [2007-10-2 0:42:56]
# 1
> smoothly but smoothly. I want it to move smoothly andCorrection : "Smoothly but SLowly" above
Thargana at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...
# 2

Are you familiar with the concept of motion blur?

In movies, especially in some action scenes, you may notice this kind stacato-y movement. The last fight in Count of Monte Cristo comes to mind....

However, you'll see in other movies fast actions that look really nice and smooth.

What gives?

Motion blur.

For stacatto-y type pictures, the film camera has a very fast shutter, only letting in light for tiny amount of time. This means there is little to no motion blur. If the shutter is left longer, you get a nice kind of motion blur going. (I hope you understand why). (Think about what happens when you don't hold a still camera steady when you take a picture).

Basically, what you have is fast shutter speed in your game. You're moving a sprite quite a bit of distance with 0 motion blur.

You want to move you images across the screen smoothly without having a stacatto type effect? You've got two choices:

1) Take smaller steps but update the steps and refresh the screen more often.

2) Simulate motion blur.

I hope that helps. :)

Viruma at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...
# 3

To get a smooth animation you need a framerate over 20 fps, so you need to increase your frame rate over 20 fps your animation will always look smooth with any speed you use.

You can also try to make your animation time-based rather than frame-based :

You say : X = X+Speed

It is always better to do ( because framerate is never consant and time is always

constant.)

X = Xstart + Speed*(System.currentTimeMillis()-timeStart);

I hope this will help you

DzzDa at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...
# 4
Thanks guys, I'll give it a go
Thargana at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...
# 5

In relation to:

X = Xstart + Speed*(System.currentTimeMillis()-timeStart);

Maybe use System.nanoTime() (java 1.5) instead because System.currentTimeMillis() is very grainy (55ms accuracy only) on windows systems.

Using currentTimeMillis() will mean that often 0 will be returned and just as often 70 or so will be returned when the real time elapsed between frames is 35ms. Remeber that there are 1000000000 nanoseconds in a second.

CommanderKeitha at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...
# 6

Yes, you are right but at 25 fps (and it is not the case) time between two frame is about 40ms so currentTimeMillis will be different each frame and for a longer time it will be constant and very near to nanoTime (less than 16ms) , and his soft will be compatible with older java and avoid java version detecting or plugin update for user.

(I am not sure but minimum interval with currentTimeMillis on windows platform is about 16ms)

DzzD

DzzDa at 2007-7-15 16:57:38 > top of Java-index,Other Topics,Java Game Development...