Function load

  • Load a single asset (to be used if you need to load additional asset(s) during the game)

    Parameters

    • asset: object
    • Optionalonload: Function

      function to be called when the asset is loaded

    • Optionalonerror: Function

      function to be called in case of error

    Returns number

    the amount of corresponding resource to be preloaded

    loader

    // load an image asset
    me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, () => this.onload(), () => this.onerror());
    // load a base64 image asset
    me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
    // load a base64 video asset
    me.loader.load({
    name: "avatar",
    type:"video",
    src: "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZ.."
    };
    // start loading music
    me.loader.load({
    name : "bgmusic",
    type : "audio",
    src : "data/audio/"
    }, function () {
    me.audio.play("bgmusic");
    });