ReferenceError: applyText is not defined #609
Answered
by
almostSouji
KaminoCodes
asked this question in
Q&A
-
When I try to emulate a user joining, I get the error ReferenceError: applyText is not defined . |
Beta Was this translation helpful? Give feedback.
Answered by
almostSouji
Feb 23, 2021
Replies: 1 comment
-
// Pass the entire Canvas object because you'll need to access its width, as well its context
const applyText = (canvas, text) => {
const ctx = canvas.getContext('2d');
// Declare a base size of the font
let fontSize = 70;
do {
// Assign the font to the context and decrement it so it can be measured again
ctx.font = `${fontSize -= 10}px sans-serif`;
// Compare pixel width of the text to the canvas minus the approximate avatar size
} while (ctx.measureText(text).width > canvas.width - 300);
// Return the result to use in the actual canvas
return ctx.font;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
almostSouji
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
applyText
is a function we define in the respective guide section, if you get that error you skipped that part of the guide. https://discordjs.guide/popular-topics/canvas.html#adding-in-text