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

public class ImageSprite
extends Sprite

An image-based sprite. The image can be an AnimatedImage. To ignore the CoreImage's hotspot, call Sprite.setAnchor(int) with an anchor other than Sprite.DEFAULT, like Sprite.NORTH_WEST.

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


Field Summary
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, 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.
protected  int getAnchorX()
           
protected  int getAnchorY()
           
 CoreImage getImage()
          Gets this ImageSprite's internal image.
protected  int getNaturalHeight()
           
protected  int getNaturalWidth()
           
 boolean getPixelLevelChecks()
          Returns true if this sprite should use pixel-level checks for intersections and picking.
protected  boolean isTransparent(int localX, int localY)
          Checks if the pixel at the specified integer location is transparent.
 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, getAnchor, getBlendMode, getCursor, getDirtyRect, getLocalX, getLocalY, getParent, getRoot, getScene2D, 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, propertyChange, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setBlendMode, setCursor, setDirty, setLocation, setLocation, setSize, setSize, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getImage

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


setImage

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


setImage

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


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

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()
Overrides:
getNaturalWidth in class Sprite

getNaturalHeight

protected int getNaturalHeight()
Overrides:
getNaturalHeight in class Sprite

getAnchorX

protected int getAnchorX()
Overrides:
getAnchorX in class Sprite
Returns:
the fixed-point x anchor.

getAnchorY

protected int getAnchorY()
Overrides:
getAnchorY in class Sprite
Returns:
the fixed-point y anchor.

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, 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.

Specified by:
drawSprite in class Sprite

PulpCore

Copyright © 2007-2008 Interactive Pulp, LLC.