New type of sprite that wraps an animation. This is useful for moving animations. It's also useful, thanks to some wackiness in the MediaPanel for making animations appear in appropriate places in the render order compared to sprites.

I'd really prefer to put this in the sprite package, but putting it here means I don't have to publicize the willStart/willFinish/didFinish functions on Animation.  I'm open to suggestions for better solutions to that one...


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@96 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2006-12-16 00:51:03 +00:00
parent e7d9acdad6
commit 493e1f1a8b
2 changed files with 73 additions and 1 deletions
@@ -239,7 +239,7 @@ public abstract class AbstractMedia
/**
* Initialize the media.
*/
protected final void init (AbstractMediaManager manager)
public final void init (AbstractMediaManager manager)
{
_mgr = manager;
init();
@@ -0,0 +1,72 @@
package com.threerings.media.animation;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import com.threerings.media.AbstractMediaManager;
import com.threerings.media.MediaPanel;
import com.threerings.media.sprite.Sprite;
import com.threerings.media.animation.Animation;
import com.threerings.media.animation.AnimationAdapter;
import com.threerings.media.animation.AnimationObserver;
/**
* A Sprite that wraps an animation so that a sequence of frames can be easily
* moved around the screen. Animations embedded here should not be added
* directly to a media panel as this sprite will manage them. If the enclosed
* animation completes, we remove the sprite from the media panel, since the
* animation would normally do that itself.
*/
public class AnimationSprite extends Sprite
{
public AnimationSprite (Animation anim, MediaPanel owner)
{
super();
_anim = anim;
_owner = owner;
}
public void init ()
{
_anim.init(_mgr);
}
// documentation inherited
public void tick (long tickStamp)
{
super.tick(tickStamp);
_anim.tick(tickStamp);
if (_anim.isFinished()) {
_anim.willFinish(tickStamp);
_owner.removeSprite(AnimationSprite.this);
_anim.didFinish(tickStamp);
} else {
_bounds = (Rectangle)_anim.getBounds().clone();
}
}
// documentation inherited.
public void setLocation (int x, int y)
{
_anim.setLocation(x, y);
super.setLocation(x, y);
}
// documentation inherited
public void willStart (long tickStamp)
{
super.willStart(tickStamp);
_anim.willStart(tickStamp);
}
// documentation inherited
public void paint (Graphics2D gfx) {
// Nothing to paint for ourselves.
_anim.paint(gfx);
}
protected Animation _anim;
protected MediaPanel _owner;
}