@Davide I am investigating how this example of overlaying animations over UI components is done <link redacted>
I'm trying to do the same thing, but putting the animated characters inside the boxes below so it looks like a sticker pack.
I copied the code and it places the animated character on the top left corner of the box. However, I'm trying to put it inside the box and I'm not sure how to adjust the code because I don't understand it. I was wondering if you could explain what each step of the code is doing here so I can figure out how to customize it myself. Specifically, I'm not sure what worldToScreen
and what the custom drawSkeleton function is doing with the verticies.
render(canvas) {
let renderer = canvas.renderer;
renderer.resize(spine.ResizeMode.Expand);
canvas.clear(0, 0, 0, 0);
renderer.begin();
// webgl canvas center
const vec3 = new spine.Vector3(0, 0);
renderer.camera.worldToScreen(vec3, canvas.htmlCanvas.clientWidth, canvas.htmlCanvas.clientHeight);
// loop over the skeleton/div comination
for (let { divs, skeleton } of Object.values(this.selectorToDiv)) {
// loop over each div where to render the current skeleton
for (let div of divs) {
const rect = div.getBoundingClientRect();
rect.x *= window.devicePixelRatio;
rect.y *= window.devicePixelRatio;
renderer.drawSkeleton(skeleton.skeleton, true, -1, -1, (vertices, size, vertexSize) => {
for (let i = 0; i < size; i+=vertexSize) {
vertices[i] = vertices[i] + rect.x - vec3.x * window.devicePixelRatio;
vertices[i+1] = vertices[i+1] - rect.y + vec3.y * window.devicePixelRatio;
}
});
}
}
// Complete rendering.
renderer.end();
}
}
Thanks!