PulpCore

pulpcore.image
Class AnimatedImage

java.lang.Object
  extended by pulpcore.image.CoreImage
      extended by pulpcore.image.AnimatedImage

public class AnimatedImage
extends CoreImage

An AnimatedImage is a CoreImage that contains multiple frames of animation. Frames are either physical or virtual.


Constructor Summary
AnimatedImage(AnimatedImage image)
          Creates a copy of the specified AnimatedImage.
AnimatedImage(CoreImage[] frames)
          Creates an AnimatedImage from a list of images.
AnimatedImage(CoreImage image, int numFramesAcross, int numFramesDown)
          Creates an AnimatedImage by spliting a image into frames on a grid.
 
Method Summary
 CoreImage background(int argbColor)
           
 CoreImage crop(int x, int y, int w, int h)
          Creates a cropped version of this image.
 CoreImage fade(int alpha)
           
 CoreImage flip()
          Returns a new CoreImage whose raster data represents a flipped version of this image.
 int getDuration()
          Gets the total duration of this AnimatedImage.
 int getDuration(int frame)
          Gets the duration of the specified virtual frame.
 int getFrame()
          Gets the current frame.
 CoreImage getImage(int frame)
          Gets the image for the specified virtual frame.
 int getNumFrames()
          Gets the number of frames in this AnimatedImage.
 CoreImage halfSize()
          Returns a new CoreImage whose raster data represents a 50% scaled version of this image.
 boolean isLooping()
          Returns true if this AnimatedImage loops.
 boolean isPlaying()
          Returns true if this AnimatedImage is currently playing.
 CoreImage mirror()
          Returns a new CoreImage whose raster data represents a mirrored version of this image.
 void pause()
          Stops the animation without changing the current frame.
 CoreImage rotate(int angle, boolean sizeAsNeeded)
          Creates a rotated version of this image.
 CoreImage rotate180()
          Returns a new CoreImage whose raster data represents this image rotated 180 degrees.
 CoreImage rotateLeft()
          Returns a new CoreImage whose raster data represents this image rotated to the left (counter-clockwise 90 degrees).
 CoreImage rotateRight()
          Returns a new CoreImage whose raster data represents this image rotated to the right (clockwise 90 degrees).
 CoreImage scale(int scaledFrameWidth, int scaledFrameHeight)
          Returns a new CoreImage whose raster data represents a scaled version of this image.
 void setFrame(int frame)
          Sets the current frame.
 void setFrameDuration(int duration, boolean loop)
          Sets the duration for each physical frame, and optionally sets the animation to loop.
 void setSequence(int[] frameSequence, int[] frameDuration, boolean loop)
          Sets the frame sequence (virtual frames), the duration for each virtual frame, and optionally sets the animation to loop.
 CoreImage setTransparentColor(int rgbColor)
          Returns a new CoreImage with all the opaque pixels of the specified color set to transparent.
 void start()
          Starts playing the animation.
 void stop()
          Stops the animation and sets the frame to zero.
 CoreImage tint(int rgbColor)
          Returns a new CoreImage with every color set to the specified color, without changing the alpha of each color.
 boolean update(int elapsedTime)
          Does nothing by default.
 
Methods inherited from class pulpcore.image.CoreImage
createGraphics, expandCanvas, expandCanvas, getARGB, getBrokenImage, getData, getHeight, getHotspotX, getHotspotY, getWidth, isOpaque, isTransparent, load, rotate, rotate, rotate, scale, setHotspot, split, split
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimatedImage

public AnimatedImage(CoreImage[] frames)
Creates an AnimatedImage from a list of images. The internal raster data array is shared.

Throws:
IllegalArgumentException - if not all the images have the same dimensions.

AnimatedImage

public AnimatedImage(AnimatedImage image)
Creates a copy of the specified AnimatedImage. The internal raster data array is shared.


AnimatedImage

public AnimatedImage(CoreImage image,
                     int numFramesAcross,
                     int numFramesDown)
Creates an AnimatedImage by spliting a image into frames on a grid.

Method Detail

setFrameDuration

public void setFrameDuration(int duration,
                             boolean loop)
Sets the duration for each physical frame, and optionally sets the animation to loop. Virtual frames are not used.


setSequence

public void setSequence(int[] frameSequence,
                        int[] frameDuration,
                        boolean loop)
Sets the frame sequence (virtual frames), the duration for each virtual frame, and optionally sets the animation to loop.

Parameters:
frameSequence - an array where each element points to an index in the list of physical frames. Can be null.
frameDuration - the duration of each virtual frame. If frameSequence is not null, frameDuration must be the same length as frameSequence. If frameSequence is null, frameDuration must be the same length as the number of physical frames.

isLooping

public boolean isLooping()
Returns true if this AnimatedImage loops.


getNumFrames

public int getNumFrames()
Gets the number of frames in this AnimatedImage. If this AnimatedImage has virtual frames, this method returns the number of virtual frames. Otherwise, the number of physical frames is returned.


getDuration

public int getDuration()
Gets the total duration of this AnimatedImage.


getDuration

public int getDuration(int frame)
Gets the duration of the specified virtual frame.


getImage

public CoreImage getImage(int frame)
Gets the image for the specified virtual frame.


setFrame

public void setFrame(int frame)
Sets the current frame.


getFrame

public int getFrame()
Gets the current frame.


update

public boolean update(int elapsedTime)
Description copied from class: CoreImage
Does nothing by default. Subclasses can use this method for dynamically generated images or animations.

Overrides:
update in class CoreImage
Returns:
true if the image changed since the last call to this method.

isPlaying

public boolean isPlaying()
Returns true if this AnimatedImage is currently playing.

See Also:
start(), stop(), pause()

start

public void start()
Starts playing the animation. By defauly, an AnimatedImage is started on creation; this method is useful after calling stop() or pause().

See Also:
isPlaying(), stop(), pause()

pause

public void pause()
Stops the animation without changing the current frame.

See Also:
isPlaying(), start(), stop()

stop

public void stop()
Stops the animation and sets the frame to zero.

See Also:
isPlaying(), start(), pause()

crop

public CoreImage crop(int x,
                      int y,
                      int w,
                      int h)
Description copied from class: CoreImage
Creates a cropped version of this image. The raster data is not shared. The hotspot is copied as-is, with no translation.

Overrides:
crop in class CoreImage

rotate

public CoreImage rotate(int angle,
                        boolean sizeAsNeeded)
Description copied from class: CoreImage
Creates a rotated version of this image.

Overrides:
rotate in class CoreImage
Parameters:
angle - a fixed-point angle, typically in the range from 0 to CoreMath.TWO_PI.
sizeAsNeeded - if true, the resulting image is sized to contain the entire rotated image. If false, the resulting image is the same size as this image. The hotspot is rotated accordingly.

halfSize

public CoreImage halfSize()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents a 50% scaled version of this image. This method uses a weighted average instead of bilinear interpolation. The hotspot is scaled accordingly.

Overrides:
halfSize in class CoreImage

scale

public CoreImage scale(int scaledFrameWidth,
                       int scaledFrameHeight)
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents a scaled version of this image. The hotspot is scaled accordingly.

Overrides:
scale in class CoreImage

mirror

public CoreImage mirror()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents a mirrored version of this image. The hotspot is mirrored accordingly.

Overrides:
mirror in class CoreImage

flip

public CoreImage flip()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents a flipped version of this image. The hotspot is flipped accordingly.

Overrides:
flip in class CoreImage

rotateLeft

public CoreImage rotateLeft()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents this image rotated to the left (counter-clockwise 90 degrees). The hotspot is rotated accordingly.

Overrides:
rotateLeft in class CoreImage

rotateRight

public CoreImage rotateRight()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents this image rotated to the right (clockwise 90 degrees). The hotspot is rotated accordingly.

Overrides:
rotateRight in class CoreImage

rotate180

public CoreImage rotate180()
Description copied from class: CoreImage
Returns a new CoreImage whose raster data represents this image rotated 180 degrees. The hotspot is rotated accordingly.

Overrides:
rotate180 in class CoreImage

setTransparentColor

public CoreImage setTransparentColor(int rgbColor)
Description copied from class: CoreImage
Returns a new CoreImage with all the opaque pixels of the specified color set to transparent.

Overrides:
setTransparentColor in class CoreImage
Parameters:
rgbColor - The color to convert to transparent. The alpha component is ignored.
Returns:
the new image.

tint

public CoreImage tint(int rgbColor)
Description copied from class: CoreImage
Returns a new CoreImage with every color set to the specified color, without changing the alpha of each color. This method is useful for creating a variety of colored fonts or for creating a solid-color stencil of a sprite.

Overrides:
tint in class CoreImage

background

public CoreImage background(int argbColor)
Overrides:
background in class CoreImage

fade

public CoreImage fade(int alpha)
Overrides:
fade in class CoreImage

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.