Link to the project or level: Text Box Bug
What I expect to happen: As I read the documentation for the
text() block, the 4th and 5th parameters should define the lower right corner of a text box, and the text (1st parameter) should be wrapped within that box.
What actually happens: The text is wrapped, but the right margin is not respected.
What I’ve tried: I reread the documentation several times , then I created a simple test case based on the sample code in the docs (above) and experimented with the values of
textH to see if I could discern a pattern. So far I’m stumped.
Here’s the code:
var textX = 100; var textY = 100; var textW = 150; var textH = 200; var textBoxContents = "I think this text should be left aligned in a box with its upper left corner at (" + textX + ", " + textY + ") and its lower right corner at (" + (textX + textW) + ", " + (textY + textH) + "). But, it's not, the text is wrapped, but it's outside of the right margin.\n\n" + "What am I doing wrong?"; // Margins to show where I think the text should be. stroke("red"); line(textX, 0, textX, 400); // Left line(0, textY, 400, textY); // Top line(textX + textW, 0, textX + textW, 400); // Right line(0, textY + textH, 400, textY + textH); // Bottom // Sample text noStroke(); fill("black"); text(textBoxContents, textX, textY, textX + textW, textY + textH);