AnimationObserver
From Gardenwiki
AnimationObserver is an easy way trigger an event when an animation finishes.
Here is the way GCPP Pickerel uses AnimationObserver.
1. Import com.threerings.media.animation.Animation and com.threerings.media.animation.AnimationObserver .
2. We add AnimationObserver to the list of interfaces that PickerelBoardView implements:
public class PickerelBoardView extends VirtualMediaPanel
implements PlaceView, SetListener, AttributeChangeListener,
MouseMotionListener, MouseListener, AnimationObserver {
3. In the PickerelBoardView class, the following variable is added so that we can refer to the specific animation we wish to observe.
/** Gleaming area on finished rows right before they are cut off */ private GleamAnimation gleamRows;
4. In the PickerelBoardView class, the following methods are added:
// from AnimationObserver
public void animationStarted(Animation anim,
long when) {}
// from AnimationObserver
public void animationCompleted(Animation anim,
long when)
{
if (anim.equals((Animation)gleamRows))
{
if (_gameobj.verbose)
log.info("gleamRows Completed");
cutOffCloth();
moveDown();
}
else if (_gameobj.verbose)
log.info("Animation Completed, not gleamRows");
} // end animationCompleted
You would customize the animationCompleted() method to look for the specific animation that you wish to use as a trigger. Pickerel uses the gleamRows GleamAnimation to trigger two methods: cutOffCloth() and moveDown(). The rows marked will gleam, then after the GleamAnimation finishes, the cloth is cut off, and remaining tiles on the loom move down.
5. At the appropriate place, add the gleamRows GleamAnimation. Note that we must specifically add the AnimationObserver to the animation. The variable theseRows is an ImageSprite.
gleamRows = new GleamAnimation(_spriteManager,
theseRows,
Color.WHITE, 2000, 2000, true);
gleamRows.addAnimationObserver(this);
addAnimation(gleamRows);

