Use a linear drag animation in response to a drag gesture to move an object to a new position specified by a coordinate. The movement follows a linear trajectory and is based on constant speed at a fixed frame rate.
To trigger a linear drag animation, use the FrameAnimator.drag
method:
FrameAnimator.drag(int x, int y);
The method takes the following parameters:
x
specifies the target x-coordinate for the
animation.
y
specifies the target y-coordinate for the
animation.
Linear drag animations are instantaneous and fixed, so they ignore
the maxFps
and maxPps
parameters
passed in the FrameAnimator.register
call. However, since
the maxFps
parameter controls how often the FrameAnimatorListener.animate
method is called,
the parameter nevertheless has an impact on quick and successive drag
animations: the lower the maxFps
value, the shorter
the drag distance, and vice versa.
As a rule, each call to the drag
method generates
exactly one call to the animate
method. This allows
the MIDlet to provide all the UI update code inside a single animate
call. However, if the MIDlet makes too many drag
calls in quick succession, the platform may skip some
calls to animate
, resulting in missing drag animations.
To avoid this, consider implementing counters for keeping track of the distance
moved after each animate
call.