It's not kosher to set a sprite's location until after it is fully

constructed. The reason being that derived classes want to override things
like updateRenderOrigin() which should be called every time the sprite's
location is set, but if we do it in the base class constructor, a derived
class's updateRenderOrigin() will be called before the derived class's
constructor has been called. This is not good. Neither was the existing
code which simply half-assed a location change by updating the sprite's
origin position but not calling updateRenderOrigin(), leaving things
generally confuzzled.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1559 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-07-08 21:15:35 +00:00
parent 6260633ec3
commit db0c1b59b8
3 changed files with 17 additions and 52 deletions
@@ -1,5 +1,5 @@
//
// $Id: ImageSprite.java,v 1.9 2002/06/20 21:42:53 mdb Exp $
// $Id: ImageSprite.java,v 1.10 2002/07/08 21:15:35 mdb Exp $
package com.threerings.media.sprite;
@@ -39,28 +39,15 @@ public class ImageSprite extends Sprite
public static final int TIME_BASED = 2;
/**
* Constructs an image sprite without any associated frames and with a
* default initial location of <code>(0, 0)</code>. The sprite should
* be populated with a set of frames used to display it via a
* subsequent call to {@link #setFrames}, and its location updated
* with {@link #setLocation}.
* Constructs an image sprite without any associated frames and with
* an invalid default initial location. The sprite should be populated
* with a set of frames used to display it via a subsequent call to
* {@link #setFrames}, and its location updated with {@link
* #setLocation}.
*/
public ImageSprite ()
{
this(0, 0, null);
}
/**
* Constructs an image sprite without any associated frames. The
* sprite should be populated with a set of frames used to display it
* via a subsequent call to {@link #setFrames}.
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
*/
public ImageSprite (int x, int y)
{
this(x, y, null);
this(null);
}
/**
@@ -70,10 +57,8 @@ public class ImageSprite extends Sprite
* @param y the sprite y-position in pixels.
* @param frames the multi-frame image used to display the sprite.
*/
public ImageSprite (int x, int y, MultiFrameImage frames)
public ImageSprite (MultiFrameImage frames)
{
super(x, y);
// initialize frame animation member data
_frames = frames;
_frameIdx = 0;
@@ -1,5 +1,5 @@
//
// $Id: LabelSprite.java,v 1.2 2002/06/20 09:01:28 shaper Exp $
// $Id: LabelSprite.java,v 1.3 2002/07/08 21:15:35 mdb Exp $
package com.threerings.media.sprite;
@@ -23,17 +23,6 @@ public class LabelSprite extends Sprite
*/
public LabelSprite (Label label)
{
this(0, 0, label);
}
/**
* Constructs a label sprite with the given initial position that
* renders itself with the specified label.
*/
public LabelSprite (int x, int y, Label label)
{
super(x, y);
_label = label;
}
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.49 2002/06/20 21:42:53 mdb Exp $
// $Id: Sprite.java,v 1.50 2002/07/08 21:15:35 mdb Exp $
package com.threerings.media.sprite;
@@ -24,24 +24,15 @@ public abstract class Sprite
implements DirectionCodes, Pathable
{
/**
* Constructs a sprite with a default initial location of <code>(0,
* 0)</code>.
* Constructs a sprite with an initially invalid location. Because
* sprite derived classes generally want to get in on the business
* when a sprite's location is set, it is not safe to do so in the
* constructor because their derived methods will be called before
* their constructor has been called. Thus a sprite should be fully
* constructed and <em>then</em> its location should be set.
*/
public Sprite ()
{
this(0, 0);
}
/**
* Constructs a sprite initially positioned at the specified location.
*
* @param x the sprite x-position in pixels.
* @param y the sprite y-position in pixels.
*/
public Sprite (int x, int y)
{
_ox = x;
_oy = y;
}
/**
@@ -430,7 +421,7 @@ public abstract class Sprite
* sprite positions itself via a hotspot that is not the upper left
* coordinate of the sprite's bounds, the offset to the hotspot should
* be maintained in {@link #_oxoff} and {@link #_oyoff}. */
protected int _ox, _oy;
protected int _ox = Integer.MIN_VALUE, _oy = Integer.MIN_VALUE;
/** The offsets from our upper left coordinate to our origin (or hot
* spot). Derived classes will need to update these values if the