Jump to content

Text : how to "jump" a line and not having a space at the line beginning ?


bali33
 Share

Recommended Posts

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

post-10911-0-03137800-1430908324.png

Link to comment
Share on other sites

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

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;        }    }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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