q5play
    Preparing search index...

    Function load

    • 🛠 Loads a file or multiple files.

      File type is determined by file extension. q5 supports loading text, json, csv, font, audio, and image files.

      By default, assets are loaded in parallel before q5 runs draw. Use await to wait for assets to load.

      Parameters

      • ...urls: string[]

      Returns PromiseLike<any[]>

      a promise that resolves with objects

      await Canvas(200);

      let logo = load('/q5js_logo.avif');

      q5.draw = function () {
      image(logo, -100, -100, 200, 200);
      };
      await Canvas(200);
      background(0.8);

      await load('/assets/Robotica.ttf');

      textSize(28);
      text('Hello, world!', -97, 100);
      await Canvas(200);

      let [jump, retro] = await load('/assets/jump.wav', '/assets/retro.flac');

      q5.mousePressed = function () {
      if (mouseButton == 'left') jump.play();
      if (mouseButton == 'right') retro.play();
      };
      //
      await Canvas(200);
      background(0.8);
      textSize(32);

      let xml = await load('/assets/animals.xml');
      let mammals = xml.querySelectorAll('mammal');
      let y = -90;
      for (let mammal of mammals) {
      text(mammal.textContent, -90, (y += 32));
      }