Shadow20 Posted December 28, 2013 Share Posted December 28, 2013 I wanted to make a dialogue system but draw the data from xml files instead of hard coding the data, what i have so far:module dialogue_test { export class main extends Phaser.State { xml: XMLDocument; html: HTMLElement; text: string; style: Phaser.Text; preload() { this.game.load.text('NPC', 'test.xml'); this.html = this.xml.getElementById("1"); this.text = this.html.innerText; } create() { this.game.add.text(this.game.world.centerX, this.game.world.centerY, this.text, this.style); } update() { } }} and my xml file:<?xml version="1.0" encoding="utf-8" ?><dialog> <NPC id="1" name="Sir Basil"> <intro>Welcome to my humble abode</intro> </NPC></dialog>I am trying to get the loaded xml file into the xml variable i created but it cant work as it is it seems. Am i on the right track for making a dialogue system by parsing data from an xml file? Link to comment Share on other sites More sharing options...
Mike Posted December 28, 2013 Share Posted December 28, 2013 Hey, I'm not so sure that Phaser can load and parse the xml the way you try... After checking: http://gametest.mobi/phaser/docs/Phaser.Loader.html#toc42 and https://github.com/photonstorm/phaser/blob/master/src/loader/Loader.js I'm still not sure what that the loaded file is not just plain text. Also thisthis.game.load.text('NPC', 'test.xml');and then instead of thisthis.html = this.xml.getElementById("1"); since this.xml - is not set anywhere before. I'll probably will look for: var xml = game.cache.getText('NPC');So also this should go in the create function since the preload is for loading stuff. Also i just found this example which loads an html file: http://gametest.mobi/phaser/examples/_site/view_full.html?d=loader&f=load+text+file.js&t=load%20text%20file Good luck and if you make it work, please share the final code as this sounds like a something common for a lot of games. Also beside that isn't JSON file more common way of passing data for a HTML5 game as ATLAS maps and so on... Link to comment Share on other sites More sharing options...
PAEz Posted December 29, 2013 Share Posted December 29, 2013 I still haven't used Phaser, but I can help with this one You never render the xml's text to xml or dom or some other structure.Here's a real simple example for ya....http://jsbin.com/phaserXMLDialog/1/edit @Mike : Im with you, JSON rocks, but this is one of those rare times you mIgHt want to use xml just because hes going to have a lot of multi line dialogs and multi line stuff sucks in JSON to write by hand...but then he should have a tool to write that stuff and then JSON is a better choice. rich and Shadow20 2 Link to comment Share on other sites More sharing options...
Shadow20 Posted December 29, 2013 Author Share Posted December 29, 2013 @Mike: thanks for trying to help, it did help a little atleast. I dont really know if JSON would be better or not but xml seemed like an easier to understand method for this purpose from what i read. PEAz seems to agree with this as well. @PEAz: thanks a million, i tried it and it worked and you went as far as to post a working example already for anyone else with the issue Link to comment Share on other sites More sharing options...
keerth Posted February 8, 2016 Share Posted February 8, 2016 The example doesn't work any longer. Check this https://colossalcode.wordpress.com/2014/11/02/phaser-load-xml/ Link to comment Share on other sites More sharing options...
bikithalee Posted May 2, 2016 Share Posted May 2, 2016 Various ways to Parse XML Lee Link to comment Share on other sites More sharing options...
Recommended Posts