Jump to content

How to load a JSON file?


fariazz
 Share

Recommended Posts

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

  • 3 weeks later...
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');

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...