diff --git a/resources/build.properties b/resources/build.properties index cf15ea0f..e1ee767b 100644 --- a/resources/build.properties +++ b/resources/build.properties @@ -131,12 +131,12 @@ source.repository=https://github.com/mikebarkmin/processing-library-scratch.git # This is used to compare different versions of the same Library, and check if # an update is available. -library.version=15 +library.version=16 # The version as the user will see it. -library.prettyVersion=1.13.0 +library.prettyVersion=1.13.1 # The min and max revision of Processing compatible with your Library. diff --git a/src/eu/barkmin/processing/scratch/ScratchImage.java b/src/eu/barkmin/processing/scratch/ScratchImage.java index 1f0b1ca2..ddcc1d79 100644 --- a/src/eu/barkmin/processing/scratch/ScratchImage.java +++ b/src/eu/barkmin/processing/scratch/ScratchImage.java @@ -3,16 +3,20 @@ import processing.core.PImage; import processing.core.PApplet; +import java.util.HashMap; + /** * The base class for representing scratch costumes and backdrops. */ public class ScratchImage { private String name; private PImage image; - private PImage originalImage; + private final PImage originalImage; private ScratchColor tint = new ScratchColor(); private float transparency = 255; + private static final HashMap originalImages = new HashMap<>(); + /** * Construct a ScratchImage object by a name and a path to an image. * @@ -21,8 +25,8 @@ public class ScratchImage { */ public ScratchImage(String name, String imagePath) { this.name = name; - this.originalImage = ScratchStage.parent.loadImage(imagePath); - this.image = this.originalImage.copy(); + this.originalImage = ScratchImage.loadImage(imagePath); + this.image = this.originalImage; } /** @@ -32,12 +36,21 @@ public ScratchImage(String name, String imagePath) { */ public ScratchImage(ScratchImage i) { this.name = i.name; - this.image = i.image.copy(); - this.originalImage = i.originalImage.copy(); + this.image = i.image; + this.originalImage = i.originalImage; this.tint = new ScratchColor(i.tint); this.transparency = i.transparency; } + private static PImage loadImage(String path) { + PImage image = originalImages.get(path); + if (image == null) { + image = ScratchStage.parent.loadImage(path); + originalImages.put(path, image); + } + return image; + } + /** * Returns the name * diff --git a/src/eu/barkmin/processing/scratch/ScratchStage.java b/src/eu/barkmin/processing/scratch/ScratchStage.java index 32fc620c..ac55d93a 100644 --- a/src/eu/barkmin/processing/scratch/ScratchStage.java +++ b/src/eu/barkmin/processing/scratch/ScratchStage.java @@ -3,6 +3,7 @@ import processing.core.PApplet; import processing.core.PConstants; import processing.core.PGraphics; +import processing.core.PImage; import processing.event.KeyEvent; import processing.event.MouseEvent;