Hello good people of Esoteric Software & beyond.
I am working on a web project for my company. Currently it consists of HTML, CSS, Pixi and spine-webgl library. For clarification I'm not working in TS though just plain JS.
I'd need to play more than one animation that is derived from one skeleton and my problem is that if I play only one instance of this animation it is working fine but the more instances that I add the faster the animations become (2 instances are twice the speed, 3 instances even faster etc).
I've been working on this for a week now to no avail - mind you I am new to this. Here is my code (mostly derived from the examples provided via Spine)
// This is where I send animations that I want to be played
function setAnimationsToPlay(animationsToPlayArr){
if(animationsToPlayArr != null || animationsToPlayArr != undefined || animationsToPlayArr > 0){
playAnimations = true;
animationsList = animationsToPlayArr;
skeletonsPlaying = {};
for( var key of Object.keys(skeletons)){
for(let i = 0; i< animationsToPlayArr.length; i++){
let keyString = key;
let myStr = animationsToPlayArr[i][0];
if(myStr == keyString){
let newSkeleton = Object.create(skeletons[key]); // I create new object for every instance - didn't solve the problem
skeletonsPlaying[i] = newSkeleton;
}
}
lastFrameTime = Date.now() / 1000;
requestAnimationFrame(render);
}
}
else{console.log('Data missing');}
}
// Modified renderer from the example code
function render() {
let gl = ctx.gl;
let now = Date.now() / 1000;
let delta = now - lastFrameTime;
lastFrameTime = now;
gl.clear(gl.COLOR_BUFFER_BIT);
for(let i = 0; i < animationsList.length; i++){
let currentSkeletonJSON = skeletonsPlaying[i].JSON;
let valueX = animationsList[i][1];
let valueY = animationsList[i][2];
resize(currentSkeletonJSON, valueX, valueY); // So far this is working fine
// Apply the animation state based on the delta time.
let state = currentSkeletonJSON.state;
state.update(delta);
state.apply(currentSkeletonJSON.skeleton);
currentSkeletonJSON.skeleton.updateWorldTransform();
// Bind the shader and set the texture and model-view-projection matrix.
shader.bind();
shader.setUniformi(spine.Shader.SAMPLER, 0);
shader.setUniform4x4f(spine.Shader.MVP_MATRIX, mvp.values);
// Start the batch and tell the SkeletonRenderer to render the active skeleton.
batcher.begin(shader);
skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
skeletonRenderer.draw(batcher, currentSkeletonJSON.skeleton);
batcher.end();
shader.unbind();
}
playAnimations === true ? requestAnimationFrame(render) : console.log('animation stopped');
}
Any clarification or advice on this would be greatly appreciated as I am out of ideas and stuck. Thank you in advance.