Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Canvas text?
How can i put text on a canvas
1 Resposta
+ 1
You can use the `strokeText` and `fillText` methods of a `2DCanvasRenderingContext`.
For example:
```
// assuming thereās a canvas in the DOM with the id ācanvasā
const canvas = document.getElementById(ācanvasā);
const ctx = canvas.getContext(ā2dā);
ctx.fillStyle = āwhiteā; // #ffffff
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = āblackā; // #000000
ctx.font = ā20px Times New Romanā;
ctx.fillText(āHello world!ā, 10, 10);
ctx.strokeText(āHello world!ā, 10, 30);
```