Jump to content

Phaser and Spine inline resources ( loading base64 json, atlas and image)


vardanyanlg
 Share

Recommended Posts

I'm trying to embed a Spine object in a Phaser project in one file (for Playable Ads) and I'm getting problems loading an image from an atlas. I've tried various ways but nothing gives me a working result at the moment.

Right now I'm trying to cache the image before the atlas is loaded. It doesn't give any errors and seems to work with the only problem is that the Spine animation in the game doesn't map the texture - it's just bare objects with motions.

Here's the part of the upload code I'm using:

.addSpine('boy',require('../img/spineboy-pro.json'),require('../img/spineboy-pro.atlas'),require('../img/spineboy-pro.png'))

addSpine(key,vJSON,vATLAS,vPNG) {
    let splitJSONBase64 = vJSON.split( ',' );
    let JSONBase64 = splitJSONBase64[ splitJSONBase64.length - 1 ];

    let data = {name:key,atlas:vATLAS,src:atob( JSONBase64 )}

    let image = new Image()
    image.src = vPNG
    image.onload = this.onSpineAnimationLoaded.bind( this, data, image )
}
onSpineAnimationLoaded( data, image,imageKey, onLoadingComplete ) {
    let texture = new this.spine.plugin.webgl.GLTexture(
        this.game.context,
        image,
        false
      );
    this.cache.custom.spineTextures.add(data.name, texture);

    let splitAtlasBase64 = data.atlas.split( ',' );
    let atlasBase64 = splitAtlasBase64[ splitAtlasBase64.length - 1 ];

    this.cache.custom.spine.add( data.name, { data: atob( atlasBase64 ) } )
    this.cache.json.add( data.name, data.src )

    this.load.spine( data.name, data.src, [atob( atlasBase64 )], true )
}

As a result, I see a complete set of data loaded from json and atlas. But I get an error when adding a Spine object to the scene: this.atlas.findRegion is not a function

if you change in the source code of SpinePlugin.js atlas = spineTextures.get(key); on the atlas = new Spine.TextureAtlas(atlasEntry.data, function () { return spineTextures.get(key); }); then the error disappears and everything works as it should. Is there some way to load the texture correctly without changing the plugin source code?

Edited by vardanyanlg
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...