bali33 Posted May 6, 2015 Share Posted May 6, 2015 Hi guys, All my game texts are saved into an XML file. Some of those text have a jump line, which is created by simply "press enter" in the XML file. Texts are correctly displayed in my game but there is always a space before the first line character after a jump line. Any idea why ? How can I prevent that behavior ? Thank you Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2015 Share Posted May 6, 2015 For your game texts: do not press enter in your XML. Long lines are no problem and if you are entering it for better readability during editing try some editor feature like wrap lines or so. If you need line breaks when text is displayed in game do it like this with "\n": This\ntext\nwill be\nsplit with result:Thistextwill besplit Link to comment Share on other sites More sharing options...
bali33 Posted May 6, 2015 Author Share Posted May 6, 2015 Hi, I already tried this but when I add a "\n" in the XML the "\n" is then displayed in my text in Phaser. Any idea why ? Thanks Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2015 Share Posted May 6, 2015 Hmmm... no experience with texts in XML. I am using JSON for all texts (including translations). This is short example (only two strings) from our last game (text.json file): { "TXT_SOUND": { "en": "ENABLE SOUND?", "it": "ATTIVARE IL SUONO?", "es": "ACTIVAR SONIDO?", "pt": "ACTIVAR SOM?", "fr": "ACTIVER LE SON?", "tr": "SESLERE İZİN VER", "ru": "ВКЛЮЧИТЬ ЗВУК?" }, "TXT_CONGRATS": { "en": "CONGRATULATIONS!\nYou solved all levels of\nANNIHILATE!", "it": "CONGRATULAZIONI!\nHai superato tutti i livelli di\nANNIHILATE!", "es": "Enhorabuena!\nHas pasado todos los niveles de\nANNIHILATE!", "pt": "PARABÉNS!\nResolveste todos os níveis de\nANNIHILATE!", "fr": "FELICITATIONS!\nTu as résolu tous les niveaux de\nANNIHILATE!", "tr": "Tebrikler tüm seviyeleri tamamladın!", "ru": "ПОЗДРАВЛЯЕМ!\nВы прошли все уровни игры\nANNIHILATE!" } }I am loading JSON texts like this: this.load.json("Text", "assets/text.json");BitmapText can "eat" it and display correctly. I am using all strings in game like this:var text: string = Utils.TextUtils.getText("TXT_SOUND");which calls simple utility class that returns string in correct languge based on game settings (MyGame.Global.currentLanguage):module Utils { export class TextUtils { public static game: Phaser.Game = null; // ------------------------------------------------------------------------- public static getText(aTextID: string): string { // get our localisation file contents as a JS object var loc = TextUtils.game.cache.getJSON("Text"); // check text id if (loc[aTextID] === undefined) { console.log("Invalid text ID " + aTextID); return ""; } // return the specified string in the specified language dynamically using array notation var text = loc[aTextID][MyGame.Global.currentLanguage]; if (text === undefined) { MyGame.Global.currentLanguage = "en"; text = loc[aTextID][MyGame.Global.currentLanguage]; } return text; } }} drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts