+ 3

Is it possible to place text over a rectangle in a canvas?

5th Sep 2018, 1:31 AM
Ethan Morrell
Ethan Morrell - avatar
2 Antworten
+ 6
Yes there is! Assuming that you have a variable called ctx as the context of the canvas and a set fill and stroke, then do: ctx.fillRect(0, 0, 50, 50); ctx.fillText(text, 10, 10); This will place a rectangle at (0, 0) and will end at (50, 50) and the text fill be placed at (10, 10). You can also use the font property to set the font of the text. Hope that helps!
5th Sep 2018, 5:49 AM
Rowsej
Rowsej - avatar
+ 2
Thank you very much! I'll try that now.
5th Sep 2018, 5:52 AM
Ethan Morrell
Ethan Morrell - avatar