help with new game in processing/eclipse organizing resources

Hello
I´m working on a big project in eclipse with the processing.core.* library.
And at the moment I have some problems with organizing the resources.
should I put them into a recource folder or into a package in src?
How can I access the resources?
at the moment, I´m using
app.getClass().getClassLoader().getResource("data"); and
app.sketchPath("data")
but when i export everything into a runnable jar file, it isn´t working caused by the resources.

can someone help?

Comments

  • I don't know if that's a good way to do it, but in my Java projects, I have a resource folder at the same level than the src folder, with same package structure.
    If a class needs to load a specific resource, I put it in the same package than the class, in the resource folder, of course.
    Then, I just use my ResourceUtil class to get its path...

  • edited February 2015

    it is working
    I´m saving the resources in a resource folder called res in a package called data.
    With this method, I´m creating the path for every file:

    static String getPath(String path) {
        path = ref.app.getClass().getClassLoader().getResource(path)
                .getFile();
        return path;
    }    
    

    The String path starts with "data/"

    Because I´m using G4P, I had to change the loadStyle_FromSketch method in GCustomSlider in the G4P library:

    private boolean loadStyle_FromSketch(String style) {
    
        // First attempt to locate the style inside the sketch or sketch data
        // folders
        File styleFolder = new File(winApp.dataPath(style));
        if (!styleFolder.exists())
            styleFolder = new File(winApp.sketchPath(style));
        if (styleFolder.exists()) {
            int fcount = 0;
            String[] names = new String[] { "centre.", "end_left.",
                    "end_right.", "handle.", "handle_mouseover." };
            PImage[] images = new PImage[names.length];
            File[] fileList = styleFolder.listFiles();
            for (int i = 0; i < names.length; i++) {
                for (File f : fileList) {
                    String filename = f.getName();
                    if (filename.startsWith(names[i])) {
                        images[i] = winApp.loadImage(style + "/" + filename);
                        fcount++;
                    }
                }
            }
            if (fcount != names.length)
                return false;
    
            centre = images[0];
            leftEnd = images[1];
            rightEnd = images[2];
            thumb = images[3];
            thumb_mouseover = images[4];
            return true;
        } else {
            try {/**made by Silverjust*/
                String[] names = new String[] { "centre.", "end_left.",
                        "end_right.", "handle.", "handle_mouseover." };
                PImage[] images = new PImage[names.length];
                for (int i = 0; i < names.length; i++) {
                    String path = winApp
                            .getClass()
                            .getClassLoader()
                            .getResource(
                                    "data/" + style + "/" + names[i] + "png")
                            .getFile();
                    //System.out.println(path);
                    images[i] = winApp.loadImage(path);
                }
    
                centre = images[0];
                leftEnd = images[1];
                rightEnd = images[2];
                thumb = images[3];
                thumb_mouseover = images[4];
                return true;
            } catch (Exception e) {
                return false;
            }
    
        }
    }
    
Sign In or Register to comment.