Package view
Class SpriteView
java.lang.Object
view.EntityView
view.SpriteView
- All Implemented Interfaces:
Configuration
The SpriteView class represents an EntityView specifically for actors in a
game. Sprites are defined in this context as a sequence of images that can be
sequentially drawn out on screen. The SpriteView extends EntityView and is
the visual representation assumed by EntityModels. SpriteView can be layered
by setting a layer value of the EntityModel that contains this view.
- Since:
- 1.0
- Author:
- Krish Pillai
-
Nested Class Summary
Nested classes/interfaces inherited from interface common.Configuration
Configuration.Direction -
Field Summary
Fields inherited from interface common.Configuration
AUDIO_DIR, DEFAULT_FRAME_RATE, DRAWABLE_DIR, GAMELOGGER, setViewCallChain -
Constructor Summary
ConstructorsConstructorDescriptionSpriteView(Color color) Basic entity view of 10x10 pixel dot of the specified colorSpriteView(Color color, float scale) Basic entity view of dot (10x10) with the color and scale factor applied.SpriteView(BufferedImage source) Constructor for creating a view from an imageSpriteView(BufferedImage source, float scaleX, float scaleY, int persistence) Constructor for creating a scaled image with a persistence rate.SpriteView(BufferedImage source, float scale, int persistence) Constructor for creating a scaled image with a persistence rate.SpriteView(String resource) View created from a sprite sheet.SpriteView(String resource, float scaleX, float scaleY) Creates a sprite view for the containing entity model.SpriteView(String resource, float scaleX, float scaleY, int persistence) Creates a sprite view for the containing entity model.SpriteView(String resource, float scale, int persistence) Constructor taking the name of the sprite sheet and the persistence, or the number of frames for which the same image has to be drawn.SpriteView(String resource, int persistence) Constructor taking the name of the sprite sheet and the persistence, or the number of frames for which the same image has to be drawn. -
Method Summary
Modifier and TypeMethodDescriptionintThe height of the scaled visual representation for this entity.floatReturns the angle of rotation in degreesintgetWidth()The width of the scaled visual representation for this entity.booleanReturns the state of sprite animation.booleaniterator()Generates an iterator that returns a Buffered Image with each call.static voidpreLoadSprites(String... sprites) Loading sprites (invoking setView()) during run-time can cause lag.voidsetFlipped(boolean flip) Laterally inverts the rendered spritevoidsetRotationAngle(float theta) Sets rotation angle for the visual in degrees (measured clockwise from horizontal).voidsetScaleFactor(float sx, float sy) Sets the x and y scale factorsMethods inherited from class view.EntityView
draw, drawBounds, getAnimation, getDimension, getScaleX, getScaleY, isWrappedView, setAnimation, setWrappedView
-
Constructor Details
-
SpriteView
Basic entity view of 10x10 pixel dot of the specified color- Parameters:
color- The color of the entity
-
SpriteView
Basic entity view of dot (10x10) with the color and scale factor applied. The scale factor can be used to change the dimensions of the dot.- Parameters:
color- The color of the entityscale- The magnification of the entity
-
SpriteView
View created from a sprite sheet. The sprite sheet naming convention is as follows: The name of the file should have a hyphen followed by the number of frames contained in the sprite sheet. The name should match the regular expression: "^[a-zA-Z0-9]+-[0-9]+.png$" The file should be located in the res/drawable package- Parameters:
resource- The name of the file
-
SpriteView
Constructor taking the name of the sprite sheet and the persistence, or the number of frames for which the same image has to be drawn. The name should match the regular expression: "^[a-zA-Z0-9]+-[0-9]+.png$"- Parameters:
resource- The number of frames to skip on animationpersistence- The name of the files
-
SpriteView
Constructor taking the name of the sprite sheet and the persistence, or the number of frames for which the same image has to be drawn. The name should match the regular expression: "^[a-zA-Z0-9]+-[0-9]+.png$" The sprite can be made larger or smaller by specifying a scale factor.- Parameters:
resource- The number of frames to skip on animationscale- The scale factor for the spritepersistence- The name of the files- See Also:
-
SpriteView
Creates a sprite view for the containing entity model.- Parameters:
resource- the file containing the sprite sheetscaleX- the horizontal scaling factorscaleY- the vertical scaling factor
-
SpriteView
Creates a sprite view for the containing entity model.- Parameters:
resource- the file containing the sprite sheetscaleX- the horizontal scaling factorscaleY- the vertical scaling factorpersistence- the number of frames each image in the sheet needs to be displayed
-
SpriteView
Constructor for creating a view from an image- Parameters:
source- The image- See Also:
-
SpriteView
Constructor for creating a scaled image with a persistence rate.- Parameters:
source- The source imagescale- The scale factorpersistence- Number of frames to skip sprite update- See Also:
-
SpriteView
Constructor for creating a scaled image with a persistence rate.- Parameters:
source- The source imagescaleX- The x-scale factorscaleY- The y-scale factorpersistence- Number of frames to skip sprite update
-
-
Method Details
-
preLoadSprites
Loading sprites (invoking setView()) during run-time can cause lag. SPrites can be pre-loaded by using this method.- Parameters:
sprites- comma separated list, or array of sprites to be pre-loaded- See Also:
-
iterator
Generates an iterator that returns a Buffered Image with each call. Default state is true. -
setRotationAngle
public void setRotationAngle(float theta) Sets rotation angle for the visual in degrees (measured clockwise from horizontal).- Parameters:
theta- The angle to be rotated in degrees (ccw)
-
setScaleFactor
public void setScaleFactor(float sx, float sy) Description copied from class:EntityViewSets the x and y scale factors- Overrides:
setScaleFactorin classEntityView- Parameters:
sx- Scale factor along x axissy- Scale factor along y axis
-
getWidth
public int getWidth()Description copied from class:EntityViewThe width of the scaled visual representation for this entity.- Specified by:
getWidthin classEntityView- Returns:
- width
-
getHeight
public int getHeight()Description copied from class:EntityViewThe height of the scaled visual representation for this entity.- Specified by:
getHeightin classEntityView- Returns:
- height
-
getRotation
public float getRotation()Returns the angle of rotation in degrees- Returns:
- theta The rotation angle in degrees
-
isFlipped
public boolean isFlipped()- Returns:
- the isFlipped
-
setFlipped
public void setFlipped(boolean flip) Laterally inverts the rendered sprite- Parameters:
flip- the sprite is flipped if to set to true
-
isAnimated
public boolean isAnimated()Returns the state of sprite animation.- Returns:
- state of sprite iterator
-