16 public Costume(String
name, String imagePath,
int cx,
int cy) {
18 this.rotationCenterX = cx;
19 this.rotationCenterY = cy;
21 File f =
new File(imagePath);
23 String projectRoot = System.getProperty(
"jscratch.project.root");
24 if (projectRoot !=
null) {
25 f =
new File(projectRoot, imagePath);
30 this.image = ImageIO.read(f);
33 ClassLoader cl = Thread.currentThread().getContextClassLoader();
34 if (cl ==
null) cl = getClass().getClassLoader();
36 URL url = cl.getResource(imagePath);
37 if (url ==
null && imagePath.startsWith(
"/")) {
38 url = cl.getResource(imagePath.substring(1));
40 if (url ==
null && !imagePath.startsWith(
"/")) {
41 url = cl.getResource(
"/" + imagePath);
45 this.image = ImageIO.read(url);
47 System.err.println(
"Failed to load costume: " + imagePath +
" (Checked project root: " + System.getProperty(
"jscratch.project.root") +
")");
48 this.image =
new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
51 }
catch (IOException e) {
52 System.err.println(
"Error loading costume: " + imagePath);
53 this.image =
new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);