Package role
Class SpriteModel
java.lang.Object
role.EntityModel
role.SpriteModel
- All Implemented Interfaces:
Configuration,Cloneable,Comparable<EntityModel>
This class represents the Sprite based model. It creates and sets up a view that is defined for entities represented by sprites.
- 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
ConstructorsConstructorDescriptionNo argument constructor.SpriteModel(int x, int y) The instantiated entity will be placed at the location (x,y).SpriteModel(int x, int y, int layer) The instantiated entity will be placed at the location (x,y) and on the layer (z-axis) specified. -
Method Summary
Modifier and TypeMethodDescriptionfloatReturns the rotation angle (Clockwise) set for this view.booleanTrue state (default) indicates that the sprite is animated.booleanReturns the state of the view.voidmodifySprite(BufferedImage image) Changes the sprite for this entityvoidmodifySprite(BufferedImage image, float scale, int persistence) Changes the sprite for this entityvoidmodifySprite(String resource) Changes current sprite to the specified sprite.voidmodifySprite(String resource, float scale, int persistence) Changes the sprite for this entityvoidsetAnimate(boolean animated) Keeps entity active, but stops the sprite from rolling.voidsetFlipped(boolean flip) Flips the view of this entity horizontally (lateral inversion)voidsetRotationAngle(float theta) The angle in degrees (Clockwise rotation).voidCreates and sets up a colored view for this entity.voidsetView(BufferedImage image) Creates and sets up view with the image specified.voidsetView(BufferedImage image, float scale, int persistence) Creates and sets up view with the image specified.voidSet view based on a drawable sprite sheet.voidCreates and sets up view with the image specified.voidCreates and sets up view with the image specified.voidCreates and sets up view with the image specified.toString()String representation of the entity showing unique ID, location and collision bounds.Methods inherited from class role.EntityModel
clone, collidesWith, compareTo, dispose, equals, getBearingDegrees, getBearingRadians, getCoefficientOfRestitution, getCollisionBounds, getCollisionRange, getHitboxHeight, getHitboxWidth, getID, getLayer, getMass, getName, getScaleX, getScaleY, getSpeed, getTimeToLive, getX, getXAcceleration, getXLocation, getXVelocity, getY, getYAcceleration, getYLocation, getYVelocity, hashCode, isActive, isDisposed, isGhost, isShowBounds, isVisible, isWrappedMode, poachState, resetCollisionBounds, resetEntityState, setActive, setAnimation, setCoefficientOfRestitution, setCollisionBounds, setCollisionBounds, setGhost, setLayer, setLocation, setMass, setName, setScale, setScale, setShowBounds, setTimeToLive, setVelocityDegrees, setVelocityRadians, setVisible, setWrappedMode, setXAcceleration, setXLocation, setXVelocity, setYAcceleration, setYLocation, setYVelocity
-
Constructor Details
-
SpriteModel
public SpriteModel()No argument constructor. The entity will be located at the top left corner of the canvas. -
SpriteModel
public SpriteModel(int x, int y) The instantiated entity will be placed at the location (x,y).- Parameters:
x- The x coordinate of the body centery- The y coordinate of the body center
-
SpriteModel
public SpriteModel(int x, int y, int layer) The instantiated entity will be placed at the location (x,y) and on the layer (z-axis) specified. Lower layers are obscured by higher layer numbers.- Parameters:
x- The x coordinate of the body centery- The y coordinate of the body centerlayer- the z layer on which the entity appears
-
-
Method Details
-
setView
Creates and sets up a colored view for this entity. The appearance is not backed by a real sprite. Should be invoked from onCreate(). Sets color to the specified color. This can be used for creating basic entities of a specific color.- Parameters:
color- The color to be applied to this basic entity ((10 x 10 pixel dot))- See Also:
-
GameController.enlistEntities()EntityModel.setAppearance()
-
setView
Set view based on a drawable sprite sheet. The file should be located in res/drawable. File name should have the proper format specified by the regex "^[a-zA-Z0-9]+-[0-9]+.png$"- Parameters:
resource- File containing the drawable- See Also:
-
GameController.enlistEntities()EntityModel.setAppearance()
-
setFlipped
public void setFlipped(boolean flip) Flips the view of this entity horizontally (lateral inversion)- Parameters:
flip- laterally inverts sprite if set to true
-
isFlipped
public boolean isFlipped()Returns the state of the view. True indicates lateral inversion of the view.- Returns:
- true or false indicating if the image is flipped horizontally or not
-
setView
Creates and sets up view with the image specified. The current scale factor is used. Persistence value indicates the number of frames to sustain a specific image from the sprite sheet. This is a way to correlate the animation rate of the sprite with the actual velocity of the entity. File name should have the proper format specified by the regex "^[a-zA-Z0-9]+-[0-9]+.png$"- Parameters:
resource- The name of the file (located in res/drawable)persistence- Frames to sustain view
-
setView
Creates and sets up view with the image specified. The current scale factor is used. Persistence value indicates the number of frames to sustain a specific image from the sprite sheet. This is a way to correlate the animation rate of the sprite with the actual velocity of the entity. File name should have the proper format specified by the regex "^[a-zA-Z0-9]+-[0-9]+.png$"- Parameters:
resource- The name of the file (located in res/drawable)scale- Scale factor for the imagepersistence- Frames to sustain view
-
setView
Creates and sets up view with the image specified. The current scale factor is used. Persistence value indicates the number of frames to sustain a specific image from the sprite sheet. This is a way to correlate the animation rate of the sprite with the actual velocity of the entity. File name should have the proper format specified by the regex "^[a-zA-Z0-9]+-[0-9]+.png$"- Parameters:
resource- The name of the file (located in res/drawable)scaleX- Horizontal scale factor for the imagescaleY- Vertical scale factor for the imagepersistence- Frames to sustain view
-
setView
Creates and sets up view with the image specified. Should be invoked from onCreate().- Parameters:
image- The buffered image to be rendered- See Also:
-
GameController.enlistEntities()EntityModel.setAppearance()
-
setView
Creates and sets up view with the image specified. The image is scaled and updated based on persistence value. Should be invoked from onCreate().- Parameters:
image- The buffered image to be renderedscale- Scale factor along x and y axespersistence- Frames to sustain view- See Also:
-
GameController.enlistEntities()EntityModel.setAppearance()
-
modifySprite
Changes current sprite to the specified sprite.- Parameters:
resource- the sprite sheet
-
setAnimate
public void setAnimate(boolean animated) Keeps entity active, but stops the sprite from rolling. The updateParameters() method on the entity will be invoked. The Sprite iterator goes inactive until the animated state is set true.- Parameters:
animated- true or false
-
isAnimated
public boolean isAnimated()True state (default) indicates that the sprite is animated. False indicated the sprite iterator has been disabled.- Overrides:
isAnimatedin classEntityModel- Returns:
- the state of sprite animation
-
getRotation
public float getRotation()Returns the rotation angle (Clockwise) set for this view. Angle is specified in degrees. The anchor point is the body center of the entity.- Returns:
- theta the angle of rotation in degrees
- See Also:
-
setRotationAngle
public void setRotationAngle(float theta) The angle in degrees (Clockwise rotation). The anchor point is the object center. Sets the angle by which the sprite should be rotated before rendering.- Parameters:
theta- The angle in degrees- See Also:
-
modifySprite
Changes the sprite for this entity- Parameters:
resource- the sprite sheetscale- the magnification to be appliedpersistence- the frame count for which each image in the sprite sheet should be displayed
-
modifySprite
Changes the sprite for this entity- Parameters:
image- the new image to be used for this entity
-
modifySprite
Changes the sprite for this entity- Parameters:
image- the new image to be used for this entityscale- the magnification to be appliedpersistence- the frame count for which each image in the sprite sheet should be displayed
-
toString
Description copied from class:EntityModelString representation of the entity showing unique ID, location and collision bounds.- Overrides:
toStringin classEntityModel- Returns:
- a string representation of the entity
-