fernfreak Posted September 4, 2018 Share Posted September 4, 2018 I was looking through the Loader class, and it seems that in order to load an asset, I need to name each file, like in: loader.add('example-sprites', 'example-sprite-sheet.json'); Is it possible to load all of the files in a folder without specifying each one by name? I know that I'd like to cache all the files within a specific folder, but I don't actually know what the filenames are prior to loading. If this isn't possible, what would be the best practice for this sort of situation when the files aren't known? Really appreciate any advice on this-- thanks in advance! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 4, 2018 Share Posted September 4, 2018 No, its not possible, because its web and not a local file system. Quote Link to comment Share on other sites More sharing options...
fernfreak Posted September 4, 2018 Author Share Posted September 4, 2018 Thanks for the quick response! :) in that case, do most people use some sort of manifest file, load that first, then load the files listed within? Or do they load a zip of some sort? Quote Link to comment Share on other sites More sharing options...
jonforum Posted September 4, 2018 Share Posted September 4, 2018 you need use a low-level environment for running server-side JavaScript. take a look on the module node.js. "nwjs" It allow you to scan your systems files and make a files list for the loader. http://www.monitis.com/blog/6-node-js-recipes-working-with-the-file-system/ and the official doc, but not completed. http://docs.nwjs.io/en/latest/ Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 4, 2018 Share Posted September 4, 2018 Yes, most people just make a manifest file Quote Link to comment Share on other sites More sharing options...
Igor Georgiev Posted August 22, 2019 Share Posted August 22, 2019 How about a script like this: var fs = require("fs"); var list = fs.readdirSync("game/static/assets/audio"); var dynamicAssets = "{\n \"paths\":\n ["; for (var i = 0; i < list.length; i++) { dynamicAssets += "\n \"/assets/audio/" + list[i] + "\","; } dynamicAssets = dynamicAssets.substr(0, dynamicAssets.length - 1) + "\n ]\n}"; fs.open('build/dynamicAssets.json', 'wx', (err, fd) => { if (err) { if (err.code === 'EEXIST') { console.log('dynamicAssets.json already exists'); return; } throw err; } fs.write(fd, dynamicAssets); }); and then you load them like this: let bootLoader = new PIXI.loaders.Loader(); bootLoader.add('dynamicAssets', 'dynamicAssets.json?version=' + version) let dynamicAssetPaths = this.app.bootLoader.resources.dynamicAssets.data.paths; for (let assetIdx=0; assetIdx < dynamicAssetPaths.length; assetIdx++) { let assetPath = dynamicAssetPaths[assetIdx]; let regExp = /([^\/\\&\?]+\.\w{3,4})/g; let assetName = regExp.exec(assetPath)[1]; PIXI.loader.add(assetName, "." + assetPath + "?version=" + version, {loadType:"XHR", xhrType:"blob"}); } fuR, themoonrat and ivan.popelyshev 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.