diff options
author | Pacien TRAN-GIRARD | 2015-11-25 17:10:17 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-25 17:10:17 +0100 |
commit | 43c5d1cb303955c1ac2fa5ac86449e87916a0257 (patch) | |
tree | edb971e375377dcbbe5153d19ce807b47c4f5036 | |
parent | aaa791e77c16585fc4011a63ed9ce33376d4784c (diff) | |
download | maze-solver-43c5d1cb303955c1ac2fa5ac86449e87916a0257.tar.gz |
Import Animation class to fix asset retrieval
-rw-r--r-- | src/ch/epfl/maze/graphics/Animation.java | 14 |
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 | */ |
26 | public final class Animation { | 25 | public 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(); |