summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ch/epfl/maze/graphics/Animation.java14
1 files changed, 10 insertions, 4 deletions
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;
21 * of animals. 21 * of animals.
22 * 22 *
23 * @author EPFL 23 * @author EPFL
24 * @author Pacien TRAN-GIRARD
25 */ 24 */
26public final class Animation { 25public final class Animation {
27 26
@@ -220,15 +219,22 @@ public final class Animation {
220 */ 219 */
221 private BufferedImage loadImage(Animal animal) { 220 private BufferedImage loadImage(Animal animal) {
222 // path = "img/superclass/class.png" 221 // path = "img/superclass/class.png"
223 String folder = animal.getClass().getSuperclass().getSimpleName(); 222 Class<?> superClass = animal.getClass().getSuperclass();
223 File f = new File("");
224 String file = animal.getClass().getSimpleName(); 224 String file = animal.getClass().getSimpleName();
225 String path = "img/" + folder + File.separator + file + ".png"; 225 String folder = "";
226 while (superClass != null && !f.exists()) {
227 folder = superClass.getSimpleName();
228 String path = "img/" + folder + File.separator + file + ".png";
229 f = new File(path);
230 superClass = superClass.getSuperclass();
231 }
226 232
227 // adds image to buffer if not already there 233 // adds image to buffer if not already there
228 BufferedImage img = mImages.get(folder + "." + file); 234 BufferedImage img = mImages.get(folder + "." + file);
229 if (img == null) { 235 if (img == null) {
230 try { 236 try {
231 img = ImageIO.read(new File(path)); 237 img = ImageIO.read(f);
232 mImages.put(folder + "." + file, img); 238 mImages.put(folder + "." + file, img);
233 } catch (IOException e) { 239 } catch (IOException e) {
234 e.printStackTrace(); 240 e.printStackTrace();