fariazz Posted May 10, 2018 Share Posted May 10, 2018 Does anyone know how to load a json file in the preload method in Phaser 3? The JSON folder of the examples in the Loader class are empty so I'm a bit stuck: http://labs.phaser.io/index.html?dir=loader/json/&q= Link to comment Share on other sites More sharing options...
YuPi Posted May 10, 2018 Share Posted May 10, 2018 I haven't used it yet, but I guess this.load.json("yourkey", "your.json") should work. Function definition is below: json(key: string | Phaser.Loader.FileTypes.JSONFileConfig | Phaser.Loader.FileTypes.JSONFileConfig[], url?: string, dataKey?: string, xhrSettings?: XHRSettingsObject): Phaser.Loader.LoaderPlugin; Link to comment Share on other sites More sharing options...
fariazz Posted May 29, 2018 Author Share Posted May 29, 2018 On 5/10/2018 at 6:40 PM, YuPi said: I haven't used it yet, but I guess this.load.json("yourkey", "your.json") should work. Function definition is below: json(key: string | Phaser.Loader.FileTypes.JSONFileConfig | Phaser.Loader.FileTypes.JSONFileConfig[], url?: string, dataKey?: string, xhrSettings?: XHRSettingsObject): Phaser.Loader.LoaderPlugin; Thanks that worked! If it helps anyone, this is how you can then retrieve the loaded object: // in preload() this.load.json('levelData', 'assets/level.json'); // in create() let data = this.cache.json.get('levelData'); Befive.Info, mariogarranz, dranitski and 1 other 4 Link to comment Share on other sites More sharing options...
Recommended Posts