PulpCore

pulpcore.sprite
Class ImageSprite

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.ImageSprite
All Implemented Interfaces:
PropertyListener
Direct Known Subclasses:
Button, StretchableSprite

public class ImageSprite
extends Sprite

An image-based sprite. The image can be an AnimatedImage. The anchor of an ImageSprite is automatically set to the image's hotspot. To ignore the hotspot, use Sprite.setAnchor(double, double).

By default, ImageSprites use pixel-level checking for intersection tests. Use setPixelLevelChecks(boolean) to disable this feature.

If you change the pixels of this ImageSprite's CoreImage, call sprite.setDirty(true).


Field Summary
 Bool antiAlias
          Flag indicating whether the edges of this ImageSprite are anti-aliased when rotating or drawing at fractional locations.
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, anchorX, anchorY, angle, CENTER, DEFAULT, EAST, enabled, height, NORTH, NORTH_EAST, NORTH_WEST, pixelSnapping, SOUTH, SOUTH_EAST, SOUTH_WEST, visible, WEST, width, x, y
 
Constructor Summary
ImageSprite(CoreImage image, double x, double y)
          Creates an ImageSprite that has the same dimensions as the image.
ImageSprite(CoreImage image, double x, double y, double w, double h)
          Creates an ImageSprite that draws the image scaled to the specified dimensions.
ImageSprite(CoreImage image, int x, int y)
          Creates an ImageSprite that has the same dimensions as the image.
ImageSprite(CoreImage image, int x, int y, int w, int h)
          Creates an ImageSprite that draws the image scaled to the specified dimensions.
ImageSprite(String imageAsset, double x, double y)
          Creates an ImageSprite that has the same dimensions as the image.
ImageSprite(String imageAsset, double x, double y, double w, double h)
          Creates an ImageSprite that draws the image scaled to the specified dimensions.
ImageSprite(String imageAsset, int x, int y)
          Creates an ImageSprite that has the same dimensions as the image.
ImageSprite(String imageAsset, int x, int y, int w, int h)
          Creates an ImageSprite that draws the image scaled to the specified dimensions.
 
Method Summary
protected  void drawSprite(CoreGraphics g)
          Draws the sprite.
 CoreImage getImage()
          Gets this ImageSprite's internal image.
protected  int getNaturalHeight()
          Gets the fixed-point value of the Sprite's natural height.
protected  int getNaturalWidth()
          Gets the fixed-point value of the Sprite's natural width.
 boolean getPixelLevelChecks()
          Returns true if this sprite should use pixel-level checks for intersections and picking.
 boolean isOpaque()
          Returns true if this Sprite is opaque.
protected  boolean isTransparent(int localX, int localY)
          Checks if the pixel at the specified integer location is transparent.
 void propertyChange(Property p)
          On a property change this Sprite is marked as dirty.
 void setAnchor(int anchor)
          Deprecated. Compass directions are being phased out - Use Sprite.setAnchor(double, double) or setAnchorToHotSpot() instead.
 void setAnchorToHotSpot()
          Sets the anchor to the underlying image's hotspot.
 void setImage(CoreImage image)
          Sets this ImageSprite's internal image.
 void setImage(String imageAsset)
          Sets this ImageSprite's internal image.
 void setPixelLevelChecks(boolean pixelLevel)
          Sets whether this sprite should use pixel-level checking for intersections and picking.
 void update(int elapsedTime)
          Updates all of this Sprite's properties.
 
Methods inherited from class pulpcore.sprite.Sprite
bindLocationTo, bindSizeTo, clearCursor, clearDirtyRect, contains, draw, getBlendMode, getCursor, getDirtyRect, getFilter, getLocalX, getLocalY, getParent, getRoot, getScene2D, getTag, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isPick, isPickEnabledAndVisible, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, removeFromParent, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setBlendMode, setCursor, setDirty, setFilter, setLocation, setLocation, setSize, setSize, setTag, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

antiAlias

public final Bool antiAlias
Flag indicating whether the edges of this ImageSprite are anti-aliased when rotating or drawing at fractional locations. The default value is true.

Constructor Detail

ImageSprite

public ImageSprite(String imageAsset,
                   int x,
                   int y)
Creates an ImageSprite that has the same dimensions as the image.


ImageSprite

public ImageSprite(CoreImage image,
                   int x,
                   int y)
Creates an ImageSprite that has the same dimensions as the image.


ImageSprite

public ImageSprite(String imageAsset,
                   int x,
                   int y,
                   int w,
                   int h)
Creates an ImageSprite that draws the image scaled to the specified dimensions.


ImageSprite

public ImageSprite(CoreImage image,
                   int x,
                   int y,
                   int w,
                   int h)
Creates an ImageSprite that draws the image scaled to the specified dimensions.


ImageSprite

public ImageSprite(String imageAsset,
                   double x,
                   double y)
Creates an ImageSprite that has the same dimensions as the image.


ImageSprite

public ImageSprite(CoreImage image,
                   double x,
                   double y)
Creates an ImageSprite that has the same dimensions as the image.


ImageSprite

public ImageSprite(String imageAsset,
                   double x,
                   double y,
                   double w,
                   double h)
Creates an ImageSprite that draws the image scaled to the specified dimensions.


ImageSprite

public ImageSprite(CoreImage image,
                   double x,
                   double y,
                   double w,
                   double h)
Creates an ImageSprite that draws the image scaled to the specified dimensions.

Method Detail

isOpaque

public boolean isOpaque()
Description copied from class: Sprite
Returns true if this Sprite is opaque. In other words, before applying transforms and alpha, all the pixels within it's bounds are drawn and are themselves opaque.

Returns false by default.

Overrides:
isOpaque in class Sprite

getImage

public final CoreImage getImage()
Gets this ImageSprite's internal image.


setImage

public void setImage(String imageAsset)
Sets this ImageSprite's internal image. The width, height, and anchor of this ImageSprite are not changed.


setImage

public void setImage(CoreImage image)
Sets this ImageSprite's internal image. The width, height, and anchor of this ImageSprite are not changed.


setAnchor

public void setAnchor(int anchor)
Deprecated. Compass directions are being phased out - Use Sprite.setAnchor(double, double) or setAnchorToHotSpot() instead.

Sets the anchor of this Sprite. The anchor affects where the Sprite is drawn in relation to its (x, y) location, and can be one of Sprite.DEFAULT, Sprite.NORTH, Sprite.SOUTH, Sprite.WEST, Sprite.EAST, Sprite.NORTH_WEST, Sprite.SOUTH_WEST, Sprite.NORTH_EAST, Sprite.SOUTH_EAST, or Sprite.CENTER.

        NW     N     NE
          +----+----+
          |         |
        W +    *    + E
          |         |
          +----+----+
        SW     S     SE
        
The Sprite.DEFAULT anchor is equivalent to Sprite.NORTH_WEST for most Sprites (except for ImageSprites, which use the CoreImage's hotspot as the anchor). If the anchor is set to Sprite.DEFAULT, this method calls setAnchorToHotSpot().

Overrides:
setAnchor in class Sprite

setAnchorToHotSpot

public void setAnchorToHotSpot()
Sets the anchor to the underlying image's hotspot. An image's hotspot is defined at build time with a property file.


update

public void update(int elapsedTime)
Description copied from class: Sprite
Updates all of this Sprite's properties. Subclasses that override this method should call super.update().

Overrides:
update in class Sprite

propertyChange

public void propertyChange(Property p)
Description copied from class: Sprite
On a property change this Sprite is marked as dirty.

Specified by:
propertyChange in interface PropertyListener
Overrides:
propertyChange in class Sprite
Parameters:
p - the property whose value has changed.

setPixelLevelChecks

public final void setPixelLevelChecks(boolean pixelLevel)
Sets whether this sprite should use pixel-level checking for intersections and picking.


getPixelLevelChecks

public final boolean getPixelLevelChecks()
Returns true if this sprite should use pixel-level checks for intersections and picking.

Overrides:
getPixelLevelChecks in class Sprite
See Also:
setPixelLevelChecks(boolean)

getNaturalWidth

protected int getNaturalWidth()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural width. Subclasses will override this method to specify the natural width. The natural width is the width of the Sprite if no scaling is applied - for an ImageSprite, the natural width is the width of the image.

Overrides:
getNaturalWidth in class Sprite

getNaturalHeight

protected int getNaturalHeight()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural height. Subclasses will override this method to specify the natural height. The natural height is the height of the Sprite if no scaling is applied - for an ImageSprite, the natural height is the height of the image.

Overrides:
getNaturalHeight in class Sprite

isTransparent

protected boolean isTransparent(int localX,
                                int localY)
Description copied from class: Sprite
Checks if the pixel at the specified integer location is transparent. This method does not check if this sprite is enabled or visible, nor does it check its alpha value.

The default implementation always returns false. Subclasses of this class may need to override this method to return accurate results.

This method is called from Sprite.contains(int,int).

Overrides:
isTransparent in class Sprite
Parameters:
localX - integer x-coordinate in local space
localY - integer y-coordinate in local space

drawSprite

protected void drawSprite(CoreGraphics g)
Description copied from class: Sprite
Draws the sprite. The graphic context's alpha is set to this sprite's alpha, and it's translation is offset by this sprite's location. This method is not called if the sprite is not visible or it's alpha is less than or equal to zero.

This method may be called multiple times for each dirty rectangle. The clip of the graphics context will be set to the current dirty rectangle.

When the contents of this sprite change (in another words, the graphic output of this method will be different from the last time it is called), subclasses should call setDirty(true).

Implementors should not save a reference to the graphics context as it can change between calls to this method.

Specified by:
drawSprite in class Sprite

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.