Animating the Sprite
Figure 19-6 shows the visible methods in Animator.
Animator performs three core tasks:
It adds animation sequences to its schedule in response to calls from the
KeyBehaviorobject.It periodically removes an animation operation from its schedule and executes it. The execution typically changes the sprite's position and pose. A removal is triggered by the arrival of a Java 3D
WakeupOnElapsedTimeevent.It updates the user's viewpoint in response to calls from
KeyBehavior.

Figure 19-6. Public methods in the Animator class
Adding an Animation Sequence
The majority of the public methods in Animator (rotClock(), rotCounterClock(), moveLeft(), moveRight(), punch(), moveForward(), moveBackwards(), and toggleAc-tive()) execute in a similar way when called by the KeyBehavior object. They add a predefined animation sequence to a schedule (which is implemented as an ArrayList called animSchedule):
public void moveForward()
{ addAnims(forwards); }
forwards is an array of strings, which represents the animation sequence for moving the sprite forward one step:
private final static String forwards[] = {"walk1", "walk2", "stand"};
"walk1", "walk2", and so forth are the names of the 3DS files holding the sprite's pose This correspondence is used to load the models when AnimTour3D starts.
A requirement of an animation sequence is that it ends with "stand". One reason for this is that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access