-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
@TouwaStar Thanks for the discussion thread! Currently there isn't anything built into Excalibur to handle text word wrap. It's definitely something that would be a useful feature in Excalibur though! It is a tricky problem to solve for sure, I'll write up and issue around this so it can be supported 👍 A couple workarounds I can think of:
// <script src="//unpkg.com/canvas-txt"></script>
var canvasTxt = window.canvasTxt.default;
// or npm install canvas-txt --save
// import canvasTxt from 'canvas-txt'
var textGraphic = new ex.Canvas({
width: 200,
height: 200,
draw: (ctx: CanvasRenderingContext2D) => {
const txt = 'Some extra long text that should wrap properly to the next line automatically';
ctx.save();
canvasTxt.font = 'Verdana';
canvasTxt.fontSize = 20;
canvasTxt.align = 'left';
// canvasTxt.debug = true //shows debug info
canvasTxt.justify = false
canvasTxt.drawText(ctx, txt, 0, 0, 200, 200);
ctx.restore();
}
});
var textActor = new ex.Actor();
textActor.graphics.use(textGraphic);
var game = new ex.Engine({
width: 400,
height: 400
});
game.currentScene.camera.pos = ex.vec(0, 0);
game.add(textActor);
game.start(); |
Beta Was this translation helpful? Give feedback.
-
Go ahead!
…On Tue, 16 Aug 2022, 14:50 Erik Onarheim, ***@***.***> wrote:
@TouwaStar <https://github.com/TouwaStar> Awesome! Do you mind if we
reference your snippet as a starting point for an implementation?
I've created an issue for Excalibur to support this type of thing out of
the box #2463 <#2463>
—
Reply to this email directly, view it on GitHub
<#2458 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHIRIWI5VYRC7CVU2P3ZN33VZOE7VANCNFSM56J5NSNA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
You might also be interested in excalibur-extended-label (for Excalibur 0.24.x) and excalibur-text (for Excalibur 0.25+). These are built specifically for our needs and have some other differences to the built-in Excalibur text rendering, but they do also support word wrap. Other differences:
|
Beta Was this translation helpful? Give feedback.
@TouwaStar Thanks for the discussion thread! Currently there isn't anything built into Excalibur to handle text word wrap.
It's definitely something that would be a useful feature in Excalibur though! It is a tricky problem to solve for sure, I'll write up and issue around this so it can be supported 👍
A couple workarounds I can think of:
\n
and manually break into multiple lines.ex.Canvas
object to manually draw text and use a canvas text library, this one https://github.com/geongeorge/canvas-txt looks pretty good and seems to work, example below:// <script src="//unpkg.com/canvas-txt…