Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Documented SpriteSheet.
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAreAllTheseTaken committed Dec 9, 2019
1 parent 90514f3 commit 1ccd88d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions RPGOnline2/src/io/github/tomaso2468/rpgonline/SpriteSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,34 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import io.github.tomaso2468.rpgonline.render.Renderer;

/**
* A class holding an image to be used as a sprite sheet.
*
* @author Tomaso2468
*
*/
public class SpriteSheet extends Image {
/**
* The width of each sprite.
*/
private int tw;
/**
* The height of each sprite.
*/
private int th;
/**
* The sprites in this sprite sheet.
*/
private Image[][] images;

/**
* Constructs a new sprite sheet.
*
* @param renderer The renderer to use for image operations.
* @param img The image to use for this sprite sheet.
* @param tw The width of each sprite.
* @param th The height of each sprite.
*/
public SpriteSheet(Renderer renderer, Image img, int tw, int th) {
super(renderer, img);
this.tw = tw;
Expand All @@ -49,18 +73,42 @@ public SpriteSheet(Renderer renderer, Image img, int tw, int th) {
}
}

/**
* Gets the number of sprites horizontally in this sprite sheet.
*
* @return An int value.
*/
public int getHorizontalCount() {
return (int) Math.ceil(getWidth() / tw);
}

/**
* Gets the number of sprites vertically in this sprite sheet.
*
* @return An int value.
*/
public int getVerticalCount() {
return (int) Math.ceil(getHeight() / th);
}

/**
* Gets the sprite at the specified position.
*
* @param x The X position of the sprite.
* @param y The Y position of the sprite.
* @return An image.
*/
public Image getSprite(int x, int y) {
return images[y][x];
}

/**
* Gets the sprite at the specified position as a new image.
*
* @param x The X position of the sprite.
* @param y The Y position of the sprite.
* @return An image.
*/
public Image getSubImage(int x, int y) {
return getSubImage(x * tw, y * th, tw, th);
}
Expand Down

0 comments on commit 1ccd88d

Please sign in to comment.