LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
541 stars 25 forks source link

`loadFont()` and `callback` not working properly. #27

Open alterebro opened 3 months ago

alterebro commented 3 months ago

loadFont() and its callback argument don't seem to work. Loaded font is only available once the browser has cached the file, which normally happens when you open the sketch for the second time. This behaviour is even present when loadFont() is called within the preload() function. Also the callback argument is not implemented.

quinton-ashley commented 1 month ago

I fixed this issue in q5.js v2, check it out! https://q5js.org

$.loadFont = (url, cb) => {
  p._preloadCount++;
  let sp = url.split('/');
  let name = sp.at(-1).split('.')[0].replace(' ', '');
  let f = new FontFace(name, 'url(' + url + ')');
  document.fonts.add(f);
  f.load().then(() => {
    p._preloadCount--;
    if (cb) cb(name);
  });
  return name;
};