From 43c5d1cb303955c1ac2fa5ac86449e87916a0257 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 25 Nov 2015 17:10:17 +0100 Subject: Import Animation class to fix asset retrieval --- src/ch/epfl/maze/graphics/Animation.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java index 9882231..1858057 100644 --- a/src/ch/epfl/maze/graphics/Animation.java +++ b/src/ch/epfl/maze/graphics/Animation.java @@ -21,7 +21,6 @@ import java.util.TreeMap; * of animals. * * @author EPFL - * @author Pacien TRAN-GIRARD */ public final class Animation { @@ -220,15 +219,22 @@ public final class Animation { */ private BufferedImage loadImage(Animal animal) { // path = "img/superclass/class.png" - String folder = animal.getClass().getSuperclass().getSimpleName(); + Class superClass = animal.getClass().getSuperclass(); + File f = new File(""); String file = animal.getClass().getSimpleName(); - String path = "img/" + folder + File.separator + file + ".png"; + String folder = ""; + while (superClass != null && !f.exists()) { + folder = superClass.getSimpleName(); + String path = "img/" + folder + File.separator + file + ".png"; + f = new File(path); + superClass = superClass.getSuperclass(); + } // adds image to buffer if not already there BufferedImage img = mImages.get(folder + "." + file); if (img == null) { try { - img = ImageIO.read(new File(path)); + img = ImageIO.read(f); mImages.put(folder + "." + file, img); } catch (IOException e) { e.printStackTrace(); -- cgit v1.2.3