Home > Software design >  Is it possible to use HTML unicodes inside HTML canvas?
Is it possible to use HTML unicodes inside HTML canvas?

Time:05-30

I am trying to build a two-dimensional chess game and found that there are Unicode for chess pieces built into HTML, is it possible to use those inside a canvas? If so, how?

CodePudding user response:

Unicode by itself doesn't have anything to do with HTML, though HTML supports Unicode character escapes.

Regardless, you can just render text in <canvas>:

const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");

const size = 16;
ctx.font = `${size}px sans-serif`;
ctx.fillText("\u2654", 0, size); // See https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
<canvas></canvas>

  • Related