Hey everyone,
I am currently working on a Playable Ad for Facebook, and I am running into some issues when loading texture atlases.
To clarify, loading normal images is working just fine using base64 encoded images and then using scene.textures.addBase64
. But as far as I can tell, there seems to be no equivalent for texture atlases.
Does anyone know how to get texture atlases to load, given the restrictions Facebook provides?
I am using their Preview Tool to verify if it is working or not.
Thanks!
Found it, here is the code in case anyone runs into the same issue:
private loadBase64Atlas(key: string, data: string, json: object): void {
const imageElement = new Image();
imageElement.onload = () => {
this.scene.textures.addAtlas(key, imageElement, json);
this.onAssetLoaded();
};
const spriteBlob = this.base64ToBlob(data.split(',')[1], 'image/png');
imageElement.src = URL.createObjectURL(spriteBlob);
}
See here on how to create the blob from base64. The JSON passed into the function can just be a normal JSON object.
4 Likes