Package view

Class SpriteView

All Implemented Interfaces:
Configuration

public class SpriteView extends EntityView implements 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
  • Constructor Details

    • SpriteView

      public SpriteView(Color color)
      Basic entity view of 10x10 pixel dot of the specified color
      Parameters:
      color - The color of the entity
    • SpriteView

      public SpriteView(Color color, float scale)
      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 entity
      scale - The magnification of the entity
    • SpriteView

      public SpriteView(String resource)
      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

      public 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. The name should match the regular expression: "^[a-zA-Z0-9]+-[0-9]+.png$"
      Parameters:
      resource - The number of frames to skip on animation
      persistence - The name of the files
    • SpriteView

      public 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. 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 animation
      scale - The scale factor for the sprite
      persistence - The name of the files
      See Also:
    • SpriteView

      public SpriteView(String resource, float scaleX, float scaleY)
      Creates a sprite view for the containing entity model.
      Parameters:
      resource - the file containing the sprite sheet
      scaleX - the horizontal scaling factor
      scaleY - the vertical scaling factor
    • SpriteView

      public SpriteView(String resource, float scaleX, float scaleY, int persistence)
      Creates a sprite view for the containing entity model.
      Parameters:
      resource - the file containing the sprite sheet
      scaleX - the horizontal scaling factor
      scaleY - the vertical scaling factor
      persistence - the number of frames each image in the sheet needs to be displayed
    • SpriteView

      public SpriteView(BufferedImage source)
      Constructor for creating a view from an image
      Parameters:
      source - The image
      See Also:
    • SpriteView

      public SpriteView(BufferedImage source, float scale, int persistence)
      Constructor for creating a scaled image with a persistence rate.
      Parameters:
      source - The source image
      scale - The scale factor
      persistence - Number of frames to skip sprite update
      See Also:
    • SpriteView

      public SpriteView(BufferedImage source, float scaleX, float scaleY, int persistence)
      Constructor for creating a scaled image with a persistence rate.
      Parameters:
      source - The source image
      scaleX - The x-scale factor
      scaleY - The y-scale factor
      persistence - Number of frames to skip sprite update
  • Method Details

    • preLoadSprites

      public static void preLoadSprites(String... sprites)
      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

      public ViewIterator 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: EntityView
      Sets the x and y scale factors
      Overrides:
      setScaleFactor in class EntityView
      Parameters:
      sx - Scale factor along x axis
      sy - Scale factor along y axis
    • getWidth

      public int getWidth()
      Description copied from class: EntityView
      The width of the scaled visual representation for this entity.
      Specified by:
      getWidth in class EntityView
      Returns:
      width
    • getHeight

      public int getHeight()
      Description copied from class: EntityView
      The height of the scaled visual representation for this entity.
      Specified by:
      getHeight in class EntityView
      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