Added support for explicitly specifying the offset into the object tile
image that should be centered at the origin when the tile is rendered. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@826 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ObjectTile.java,v 1.4 2001/11/18 04:09:21 mdb Exp $
|
// $Id: ObjectTile.java,v 1.5 2001/12/18 08:37:54 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -49,19 +49,48 @@ public class ObjectTile extends Tile
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the object footprint width in tile units.
|
* Sets the object footprint in tile units.
|
||||||
*/
|
*/
|
||||||
public void setBaseWidth (int baseWidth)
|
public void setBase (int width, int height)
|
||||||
{
|
{
|
||||||
_baseWidth = baseWidth;
|
_baseWidth = width;
|
||||||
|
_baseHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the object footprint height in tile units.
|
* Returns the x offset into the tile image of the origin (which will
|
||||||
|
* be aligned with the bottom center of the origin tile) or -1 if the
|
||||||
|
* origin is not explicitly specified and should be computed from the
|
||||||
|
* image size and tile footprint.
|
||||||
*/
|
*/
|
||||||
public void setBaseHeight (int baseHeight)
|
public int getOriginX ()
|
||||||
{
|
{
|
||||||
_baseHeight = baseHeight;
|
return _originX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the y offset into the tile image of the origin (which will
|
||||||
|
* be aligned with the bottom center of the origin tile) or -1 if the
|
||||||
|
* origin is not explicitly specified and should be computed from the
|
||||||
|
* image size and tile footprint.
|
||||||
|
*/
|
||||||
|
public int getOriginY ()
|
||||||
|
{
|
||||||
|
return _originY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the offset in pixels to the origin in the tile image. The
|
||||||
|
* object will be rendered such that its origin is at the bottom
|
||||||
|
* center of its origin tile. If no origin is specified, the bottom of
|
||||||
|
* the image is aligned with the bottom of the origin tile and the
|
||||||
|
* left side of the image is aligned with the left edge of the
|
||||||
|
* left-most base tile.
|
||||||
|
*/
|
||||||
|
public void setOrigin (int x, int y)
|
||||||
|
{
|
||||||
|
_originX = x;
|
||||||
|
_originY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -70,8 +99,21 @@ public class ObjectTile extends Tile
|
|||||||
super.toString(buf);
|
super.toString(buf);
|
||||||
buf.append(", baseWidth=").append(_baseWidth);
|
buf.append(", baseWidth=").append(_baseWidth);
|
||||||
buf.append(", baseHeight=").append(_baseHeight);
|
buf.append(", baseHeight=").append(_baseHeight);
|
||||||
|
buf.append(", originX=").append(_originX);
|
||||||
|
buf.append(", originY=").append(_originY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The object footprint dimensions in unit tile units. */
|
/** The object footprint width in unit tile units. */
|
||||||
protected int _baseWidth, _baseHeight;
|
protected int _baseWidth = 1;
|
||||||
|
|
||||||
|
/** The object footprint height in unit tile units. */
|
||||||
|
protected int _baseHeight = 1;
|
||||||
|
|
||||||
|
/** The x offset into the tile image of the origin or -1 if the origin
|
||||||
|
* should be calculated based on the footprint. */
|
||||||
|
protected int _originX = -1;
|
||||||
|
|
||||||
|
/** The y offset into the tile image of the origin or -1 if the origin
|
||||||
|
* should be calculated based on the footprint. */
|
||||||
|
protected int _originY = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ObjectTileSet.java,v 1.5 2001/11/29 23:07:12 mdb Exp $
|
// $Id: ObjectTileSet.java,v 1.6 2001/12/18 08:37:54 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -18,29 +18,6 @@ import com.threerings.media.ImageManager;
|
|||||||
*/
|
*/
|
||||||
public class ObjectTileSet extends SwissArmyTileSet
|
public class ObjectTileSet extends SwissArmyTileSet
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Adds object data for the tile at the specified index.
|
|
||||||
*
|
|
||||||
* @param tileIndex the tile for which we are adding object data.
|
|
||||||
* @param objWidth the width of the object in tile units.
|
|
||||||
* @param objHeight the height of the object in tile units.
|
|
||||||
*/
|
|
||||||
public void addObjectData (int tileIndex, int objWidth, int objHeight)
|
|
||||||
{
|
|
||||||
// create our objects arrays if we've not already got them
|
|
||||||
if (_owidths == null) {
|
|
||||||
_owidths = new int[getTileCount()];
|
|
||||||
_oheights = new int[_owidths.length];
|
|
||||||
// initialize the default tile dimensions to one unit
|
|
||||||
Arrays.fill(_owidths, 1);
|
|
||||||
Arrays.fill(_oheights, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now fill in the appropriate slot
|
|
||||||
_owidths[tileIndex] = objWidth;
|
|
||||||
_oheights[tileIndex] = objHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the widths (in unit tile count) of the objects in this
|
* Sets the widths (in unit tile count) of the objects in this
|
||||||
* tileset. This must be accompanied by a call to {@link
|
* tileset. This must be accompanied by a call to {@link
|
||||||
@@ -61,12 +38,30 @@ public class ObjectTileSet extends SwissArmyTileSet
|
|||||||
_oheights = objectHeights;
|
_oheights = objectHeights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the x offset in pixels to the image origin.
|
||||||
|
*/
|
||||||
|
public void setXOrigins (int[] xorigins)
|
||||||
|
{
|
||||||
|
_xorigins = xorigins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the y offset in pixels to the image origin.
|
||||||
|
*/
|
||||||
|
public void setYOrigins (int[] yorigins)
|
||||||
|
{
|
||||||
|
_yorigins = yorigins;
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected void toString (StringBuffer buf)
|
protected void toString (StringBuffer buf)
|
||||||
{
|
{
|
||||||
super.toString(buf);
|
super.toString(buf);
|
||||||
buf.append(", owidths=").append(StringUtil.toString(_owidths));
|
buf.append(", owidths=").append(StringUtil.toString(_owidths));
|
||||||
buf.append(", oheights=").append(StringUtil.toString(_oheights));
|
buf.append(", oheights=").append(StringUtil.toString(_oheights));
|
||||||
|
buf.append(", xorigins=").append(StringUtil.toString(_xorigins));
|
||||||
|
buf.append(", yorigins=").append(StringUtil.toString(_yorigins));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +79,14 @@ public class ObjectTileSet extends SwissArmyTileSet
|
|||||||
hei = _oheights[tileIndex];
|
hei = _oheights[tileIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ObjectTile(image, wid, hei);
|
ObjectTile tile = new ObjectTile(image, wid, hei);
|
||||||
|
|
||||||
|
if (_xorigins != null) {
|
||||||
|
tile.setOrigin(_xorigins[tileIndex], _yorigins[tileIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tile;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The width (in tile units) of our object tiles. */
|
/** The width (in tile units) of our object tiles. */
|
||||||
@@ -92,4 +94,10 @@ public class ObjectTileSet extends SwissArmyTileSet
|
|||||||
|
|
||||||
/** The height (in tile units) of our object tiles. */
|
/** The height (in tile units) of our object tiles. */
|
||||||
protected int[] _oheights;
|
protected int[] _oheights;
|
||||||
|
|
||||||
|
/** The x offset in pixels to the origin of the tile images. */
|
||||||
|
protected int[] _xorigins;
|
||||||
|
|
||||||
|
/** The y offset in pixels to the origin of the tile images. */
|
||||||
|
protected int[] _yorigins;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ObjectTileSetRuleSet.java,v 1.2 2001/11/29 22:10:28 mdb Exp $
|
// $Id: ObjectTileSetRuleSet.java,v 1.3 2001/12/18 08:37:54 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tools.tile.xml;
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
@@ -65,6 +65,26 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
|||||||
((ObjectTileSet)target).setObjectHeights(heights);
|
((ObjectTileSet)target).setObjectHeights(heights);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
digester.addRule(
|
||||||
|
_prefix + TILESET_PATH + "/xOrigins",
|
||||||
|
new CallMethodSpecialRule(digester) {
|
||||||
|
public void parseAndSet (String bodyText, Object target)
|
||||||
|
{
|
||||||
|
int[] xorigins = StringUtil.parseIntArray(bodyText);
|
||||||
|
((ObjectTileSet)target).setXOrigins(xorigins);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
digester.addRule(
|
||||||
|
_prefix + TILESET_PATH + "/yOrigins",
|
||||||
|
new CallMethodSpecialRule(digester) {
|
||||||
|
public void parseAndSet (String bodyText, Object target)
|
||||||
|
{
|
||||||
|
int[] yorigins = StringUtil.parseIntArray(bodyText);
|
||||||
|
((ObjectTileSet)target).setYOrigins(yorigins);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
|
|||||||
Reference in New Issue
Block a user