Loading data from another directory

edited March 2015 in How To...

Hi,

My 'data' folder consist of a number of different items including textfiles, .vlw files for font, and different sets of images. Is there any way of how such files can be organised in folders within the 'data' folder and can be still accessed when for example using the loadImage() or loadFont() methods?

Thanks.

Answers

  • What happened when you just added a directory and put the directory name in front of the file name?

  • Answer ✓

    Use dataPath("folder/file_name.ext"). Some examples:

    • loadImage(dataPath("images/sprite01.png"));
    • saveFrame(dataPath("backgrounds/bg-####.jpg"));
    • loadFont(dataPath("fonts/LetterGothicStd-32.vlw"));

    P.S.: dataPath("") can be omitted when loading. But it's needed when saving! 8-}

    Therefore loadImage(dataPath("images/sprite01.png"));
    can simply be: loadImage("images/sprite01.png");

    But saveFrame(dataPath("backgrounds/bg-####.jpg")); should rely on dataPath("")! :-\"

  • Hmmm that pretty basic stuff but I didn't know it can be done that way! Big thanks both of you :)

Sign In or Register to comment.