Hi Davide,thank you!
✅ What I Have Done
Converted my .json, .atlas, and .png to Base64.
Loaded the assets using PIXI.Assets.add().
Replaced chibi-stickers-pro.png in the .atlas file with "spineImage".
Created a TextureAtlas from the .atlas file.
Assigned the correct textures from PIXI.Assets.get().
Initialized the Spine animation with spine.Spine.from(skeleton, textureAtlas, { autoUpdate: true }).
🔴 The Problem
I keep getting this error in the console:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
at Bm.get (Assets.ts:732:34)
at Spine.from (Spine.ts:892:29)
It seems that either skeleton or textureAtlas is not properly loaded, but when I log them to the console, they appear to be valid.
📜 My Current Code
const atlas_base64 = "INSERT_YOUR_ATLAS_BASE64_HERE";
const json_base64 = "INSERT_YOUR_JSON_BASE64_HERE";
const sprite_base64 = "INSERT_YOUR_PNG_BASE64_HERE";
(async function () {
var app = new PIXI.Application();
await app.init({
resizeTo: document.body,
backgroundAlpha: 0.0,
});
document.body.appendChild(app.view);
// ✅ Load the Base64 PNG as a texture
PIXI.Assets.add({
alias: 'spineImage',
src: `data:image/png;base64,${sprite_base64}`,
});
// ✅ Decode the Atlas and replace the original image name
const decodedAtlas = atob(atlas_base64).replaceAll('chibi-stickers-pro.png', 'spineImage');
const encodedAtlas = btoa(decodedAtlas);
PIXI.Assets.add({
alias: 'atlasTxt',
src: `data:plain/text;base64,${encodedAtlas}`,
loadParser: 'loadTxt',
});
// ✅ Load the JSON skeleton
PIXI.Assets.add({
alias: 'skeleton',
src: `data:application/json;base64,${json_base64}`,
loadParser: 'loadJson',
});
// 🟢 Load all assets
const { atlasTxt: loadedAtlasTxt, skeleton } = await PIXI.Assets.load(['atlasTxt', 'skeleton', 'spineImage']);
// 🚨 Debugging logs
console.log("Checking if assets are loaded:");
console.log("Skeleton:", skeleton);
console.log("Atlas Text:", loadedAtlasTxt);
if (!skeleton) {
console.error("❌ Error: Skeleton asset is missing.");
return;
}
if (!loadedAtlasTxt || loadedAtlasTxt.length === 0) {
console.error("❌ Error: Atlas text is empty or failed to load.");
return;
}
// ✅ Create the TextureAtlas
const textureAtlas = new spine.TextureAtlas(loadedAtlasTxt, (path) => {
console.log(`🔍 Looking for texture: ${path}`);
return PIXI.Assets.get("spineImage")?.baseTexture || null;
});
PIXI.Assets.cache.set('atlas', textureAtlas);
// 🚨 Check if TextureAtlas has pages
console.log("Checking TextureAtlas:", textureAtlas);
console.log("TextureAtlas Pages:", textureAtlas.pages);
if (!textureAtlas.pages || textureAtlas.pages.length === 0) {
console.error("❌ Error: TextureAtlas has no pages loaded.");
return;
}
// ✅ Assign textures to the atlas pages
for (const page of textureAtlas.pages) {
const sprite = PIXI.Assets.get("spineImage");
if (!sprite) {
console.error(`❌ Error: Texture not found for page: ${page.name}`);
continue;
}
console.log(`✅ Assigning texture to page: ${page.name}`);
page.setTexture(spine.SpineTexture.from(sprite.baseTexture));
}
// 🟢 Create the Spine instance
const spineboy = spine.Spine.from(skeleton, textureAtlas, { autoUpdate: true });
spineboy.x = app.screen.width / 2;
spineboy.y = app.screen.height / 2;
spineboy.scale.set(0.5);
// 🔹 Set animations
spineboy.skeleton.setSkinByName("soeren");
spineboy.skeleton.setSlotsToSetupPose();
spineboy.state.setAnimation(0, "wave", true);
// ✅ Add to stage
app.stage.addChild(spineboy);
})();
🔍 What I Have Checked
Skeleton is loaded correctly (confirmed in console logs).
Atlas text is loaded and contains valid Spine atlas data.
TextureAtlas is created, but the error still happens when calling Spine.from().