Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Do we have API to wrap text automatically?


dchhetri
 Share

Recommended Posts

 

 

Yes, I just created a simple animation helper todo this.

 //shows word by word animateTextShow: function(textObject,message,fps){    if(!fps || fps == 0){      textObject.setText(message);    }else{      var nextWordIndex = 1;      var id;      var words = message.split(' ');      id = setInterval(function(){        textObject.setText(words.slice(0,nextWordIndex).join(' '));        ++nextWordIndex;        if(nextWordIndex >= words.length){          clearInterval(id);        }      },1000/fps);    }  }
Link to comment
Share on other sites

  • 2 months later...

 

You can pet some properties on the style of the text to wrap it.

var style = {    //usual style things here    wordWrap: true,    wordWrapWidth: 500 //Your bounding width here.};

Thanks for this suggestion? I have a related question: the suggestion above works great, but it also wraps the words (it breaks the words). Is there a way to wrap the sentence but not the words? (just started html5, so forgive if I'm asking really dumb things here..)

i've tried to do it in CSS as well (style = { width: "500px" }; , but that doesn't work. Suggestions? Thanks in advance!

Link to comment
Share on other sites

We rolled our own text class here because we needed to do some other fancy things with text. Wrapping on words was one of them.

 

My basic early "good enough for now" solution basically tracked back from the character that PIXI tried to wrap on, and find the first space character and change the wrap point to that instead.

 

 

 

Note: Looking at the Phaser 1.2 code for the Text class, it looks like it wraps on words.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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