[Solved] Is there a way I can use images encoded as base64 data strings for sprites?

Is there a way I can use images encoded as base64 data strings for sprites? (instead of files?)

I checked the data.js and saw that the scripts are referring to images with their filenames like this:

{
          "alwaysLoaded": false,
          "file": "my_image.png",
          "kind": "image",
          "metadata": "",
          "name": "my_image.png",
          "smoothed": true,
          "userAdded": true
}

=====

EDIT: I found a way by inserting the base64 data to the above data structure and modifying some code.

2 Likes

This would be a nice feature! (It exists in Construct 2, where I used for a level editor for my game, so that the background image could be stored alongside the level data in a single JSON file.) But I’m guessing it’s too niche to become part of the official GDevelop functionality anytime soon.

Can you elaborate on how you modified the code to get it to work?

You can still follow this

It is more flexible than a base64 bundled in the app.

Thanks! Just realized I never responded to you there. The problem with that one is that if I load images that way, the Drag behavior stops working on them and I can’t seem to be able to resize them properly, either. Here, I wasn’t thinking about bundling base64 but loading it from an external text file.

Turns out that I didn’t have to modify any code.

To use Base64 image data, I just replaced the filename with the Base64 string. Like this

{
          "alwaysLoaded": false,
          "file": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAclippingTheStringHereSInceItIsTooLong",
          "kind": "image",
          "metadata": "",
          "name": "my_image.png",
          "smoothed": true,
          "userAdded": true
}

I deleted the image file to test if it works and it does. I can’t remember the name of the PIXI function that loads images/textures but I think it is overloaded so that it can take either a filename or a base64 string to load images.

1 Like

Thanks! Good to know that PIXI can handle data URI.