I'm trying to create a wheel of fortune with images instead of text to display the prices.
I am using ctx.fillText(sector.label, rad - 50, 10);
to fill all prices with their text label, but I'd like to replace the text with an image intead!
However, when I do ctax.drawImage(sector.image, rad - 50, 10)
, all the images gets rendered on the same spot.
I tried to add a loadImage
function like so:
const loadImage = (ctx, sector, ang) => {
const img = new Image();
img.onload = function () {
ctx.drawImage(img, rad - 50, 10); // Or at whatever offset you like
};
img.src = sector.image;
};
which works, but it applies all the images on the same spot.
Why is it that ctx.fillText()
positions the text correctly, but images are not?
I saw How to draw image on wheel of fortune?, but I'd like to use a canvas instead of css.