Added hitTest() which determines whether or not a point touches a
non-transparent pixel in an object's image. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@901 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
//
|
||||
// $Id: ObjectTile.java,v 1.5 2001/12/18 08:37:54 mdb Exp $
|
||||
// $Id: ObjectTile.java,v 1.6 2002/01/31 02:08:52 mdb Exp $
|
||||
|
||||
package com.threerings.media.tile;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.threerings.media.Log;
|
||||
|
||||
/**
|
||||
* An object tile extends the base tile to provide support for objects
|
||||
@@ -93,6 +96,29 @@ public class ObjectTile extends Tile
|
||||
_originY = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the object tile's bounds contain the specified
|
||||
* point, and if there is a non-transparent pixel in the tile image at
|
||||
* the specified point, false if not.
|
||||
*
|
||||
* @param x the x offset into the object tile's bounds to test.
|
||||
* @param y the y offset into the object tile's bounds to test.
|
||||
*/
|
||||
public boolean hitTest (int x, int y)
|
||||
{
|
||||
if (_image instanceof BufferedImage) {
|
||||
BufferedImage bimage = (BufferedImage)_image;
|
||||
int argb = bimage.getRGB(x, y);
|
||||
// it's only a hit if the pixel is non-transparent
|
||||
return (argb >> 24) != 0;
|
||||
|
||||
} else {
|
||||
Log.warning("Can't check for transparent pixel " +
|
||||
"[image=" + _image + "].");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void toString (StringBuffer buf)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user