ecj2 / momo

[NOT MAINTAINED / ABANDONED] A simple 2D game-making library written in JavaScript.
MIT License
1 stars 0 forks source link

Add method to draw multiple lines of text #3

Closed ecj2 closed 6 years ago

ecj2 commented 6 years ago

It would be convenient to be able to draw multiple lines of text through the use of one method call.

So instead of:

Momo.drawText(..., "first line", ...);
Momo.drawText(..., "second line", ...);
Momo.drawText(..., "third line", ...);

Just do:

Momo.drawMultiline(..., "first line<br>second line<br>third line", ...);

Maybe the line break character could be specified in the method as well.

ecj2 commented 6 years ago

Here is an example function I wrote that draws multiple lines of text on top of each other and splits the lines whenever a line break ("\n") appears:

function drawMultipleLinesOfText(font, fill_color, size, x, y, alignment, text, outline_color = undefined, outline_width = 0) {

  let lines = text.split("\n");

  let i = 0;
  let number_of_lines = lines.length;

  for (i; i < number_of_lines; ++i) {

    Momo.drawText(font, fill_color, size, x, y + (size * i), alignment, lines[i], outline_color, outline_width);
  }
}

The above is a good starting point, but I am not entirely sure that a one-size-fits-all solution would be well-suited to Momo. It might be best that the library not include such functionality, and instead allow users to roll their own implementations.

ecj2 commented 6 years ago

Users are likely better off rolling their own implementations.