-1

I am using GMS1.4 HTML5 module and i'm currently trying to import sprite images to it. The issue is i don't want to save it in the local directory and since there is a built in function that allows the sprite to be added from a URL i was thinking of just using a blob to get the job done so the temp sprite is erased from memory after the user is done with the game.

The problem is 1.4 is sandboxed so all url links and references seems to point to the Local storage. instead of

blob:http://mysite.co/85cad96e-e44e-a1f9-db97a96ed3fe

it'll preapped like this

http://mysite.co/html5game/blob:http://mysite/85cad96e-e44e-a1f9-db97a96ed3fe

Im only assuming its due to the sandbox nature of GMS and there does not seem to be a way to turn it off. my next idea is since it wants to be stubborn about using the sandbox directory, was to just create the blob within that folder. Is it possible to create at path and URL.createObjectURL?

  • [No you can't](https://stackoverflow.com/questions/41947735/custom-name-for-blob-url), you'd be better just asking the original question: how to make game-maker not preprocess your links. – Kaiido Feb 19 '20 at 06:26

1 Answers1

0

You could adapt an approach based on what I did for "Allow Data URI" to also allow blob URIs. Excerpt follows,

GML:

#define gmcallback_AllowDataURI
if (AllowDataURI()) {
    AllowDataURI(sprite_add("", 1, 0, 0, 0, 0));
}

JS:

function AllowDataURI() {
    var p0 = "\\s*\\(\\s*";
    var p1 = "\\s*\\)\\s*";
    var eq = "\\s*=\\s*";
    var id = "\\w+";
    //
    var init_js = window.gml_Script_gmcallback_AllowDataURI.toString();
    var sprite_add_js = window[
        /\bAllowDataURI\s*\(\s*(\w+)/.exec(init_js)[1] // AllowDataURI(sprite_add(...
    ].toString();
    var sprite_add_url = /function\s*\w*\s*\((\w+)/g.exec(sprite_add_js)[1];
    var sprite_add_url2 = new RegExp(
        "("+id+")"+eq+sprite_add_url+"\\b", // `sprite_add_url2 = sprite_add_url`
    "g").exec(sprite_add_js);
    sprite_add_url2 = sprite_add_url2 ? sprite_add_url2[1] : sprite_add_url;
    //
    var image_add_js = window[new RegExp(
        id+eq+"("+id+")"+p0+sprite_add_url2+p1, // `_ = image_add(sprite_add_url2)`
    "g").exec(sprite_add_js)[1]].toString();
    var image_add_url = /function\s*\w*\s*\((\w+)/g.exec(image_add_js)[1];
    //
    var url_proc = new RegExp(
        id+eq+"("+id+")"+p0+image_add_url+p1, // `_ = url_proc(image_add_url)`
    "g").exec(image_add_js)[1];
    window[url_proc] = (function() {
        var f = window[url_proc];
        return function(url) {
            if (url.substring(0, 5) == "data:") return url;
            if (url.substring(0, 5) == "blob:") return url; // new!
            return f.apply(this, arguments);
        };
    })();
    //
    return false;
}
YellowAfterlife
  • 2,967
  • 1
  • 16
  • 24