Skip to content

Commit

Permalink
* Add the useVolatileImage instance variable to the Sprite class (#…
Browse files Browse the repository at this point in the history
…10)

* Add a `@Getter` annotation to the `bufferedImage` instance variable of the `SpriteSheet` class
* Fix JavaDoc error in the `SpriteSheet` class
* Update version from `2020.01.20-FULL_REWRITE.0` to `2020.04.05`
  • Loading branch information
Valkryst authored Apr 6, 2020
1 parent 845d886 commit 5a9b5a6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Dependency:
<dependency>
<groupId>com.github.Valkryst</groupId>
<artifactId>V2DSprite</artifactId>
<version>2020.03.01</version>
<version>2020.04.05</version>
</dependency>
```

Expand Down
1 change: 1 addition & 0 deletions V2DSprite.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" isTestSource="true" generated="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="jdk" jdkName="11.0.2" jdkType="JavaSDK" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.Valkryst</groupId>
<artifactId>V2DSprite</artifactId>
<version>2020.03.01</version>
<version>2020.04.05</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/valkryst/V2DSprite/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.json.JSONObject;

public class Sprite {
/** The com.valkryst.V2DSprite.SpriteSheet containing this sprite. */
/** The SpriteSheet containing this sprite. */
private final SpriteSheet spriteSheet;

/** The x-axis position of the top-left pixel, within the sprite sheet. */
Expand All @@ -22,6 +23,13 @@ public class Sprite {
/** The height. */
@Getter private final short height;

/**
* Whether the sprite should be drawn using a
* {@link java.awt.image.VolatileImage} or a
* {@link java.awt.image.BufferedImage}.
*/
@Setter public boolean useVolatileImage = true;

/**
* Constructs a new sprite.
*
Expand Down Expand Up @@ -96,7 +104,8 @@ public JSONObject toJson() {
* The position, on the graphics context, to draw this sprite.
*/
public void draw(final @NonNull Graphics2D gc, final @NonNull Point position) {
gc.drawImage(spriteSheet.getImage(), position.x, position.y, position.x + width, position.y + height, x, y, x + width, y + height, null);
final var image = useVolatileImage ? spriteSheet.getImage() : spriteSheet.getBufferedImage();
gc.drawImage(image, position.x, position.y, position.x + width, position.y + height, x, y, x + width, y + height, null);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/valkryst/V2DSprite/SpriteSheet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.valkryst.V2DSprite;

import lombok.Getter;
import lombok.NonNull;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -19,7 +20,7 @@

public class SpriteSheet {
/** The original image, loaded from disk. */
private final BufferedImage bufferedImage;
@Getter private final BufferedImage bufferedImage;
/** The volatile image, created from the original image. */
private VolatileImage volatileImage;

Expand Down

0 comments on commit 5a9b5a6

Please sign in to comment.