klam A. Posted June 18, 2014 Share Posted June 18, 2014 Hi. English is not my native language, so sory for my mistakes. I make game in VisualStudio(TypeScript), and create levels in Tiled Map Editor. So my questions is: how I can read information in my TypeSript game from level.json file?Thanks. Quote Link to comment Share on other sites More sharing options...
Elizabeth_Keen Posted June 25, 2014 Share Posted June 25, 2014 Simplistically speaking, you could load it with an AJAX call and parse the JSON: function levelRequestListener () {var levels = JSON.parse(this.responseText);console.log(levels);}var request = new XMLHttpRequest();request.onload = levelRequestListener;request.open("get", "level.json", true);request.send(); You could take this up a level by writing an interface to describe the levels structure so you could get type checking and auto-completion on the levels variable... interface Level {id: number;name: string;}function levelRequestListener () {var levels: Level[] = JSON.parse(this.responseText);console.log(levels[0].name);} Hope this helps. Fow more applications design and development visit: http://www.ati-erp.com 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.