Search code examples
javascripteaseljscreatejs

EaselJS Word Wrapping


In many canvas frameworks there is a maxWidth and maxHeight to control word wrapping.

In EaselJS setting maxWidth is trivial but is there a way to set a maxHeight to text? (Efficiently)


Solution

  • txt.lineWidth = 200; 
    
    var txt = new createjs.Text( 'txt sdfj sdfks dflkjsd flksdjf sdklfj sdlkfjsd fkljsdfsdjkf', "21px Arial", "#000" );
    container.addChild( txt );
    var w = ( txt.getMeasuredWidth() ) * txt.scaleX;
    var h = ( txt.getMeasuredHeight() ) * txt.scaleY; 
    txt.regY = h / 2;
    txt.textAlign = 'center' 
    txt.lineWidth = 200;
    txt.x = __shape.x;
    txt.y = __shape.y;
    txt.color = 'black';