how can i replace current inited SpinePlayer skeleton, i have most 8 diifren skeletonJson and atlas,i only want to use one webgl instance to switch play then, pls give a guide,I hope to maintain good performance on mobile
how can i replace current inited SpinePlayer skeleton
To replace the current initialized skeleton in a SpinePlayer
while maintaining good performance on mobile, you can follow these steps:
Dispose of the Current Player: Use the
dispose()
method to clean up the currentSpinePlayer
instance. This will help manage resources effectively and prevent memory leaks.Reinitialize the Player: After disposing of the current player, create a new
SpinePlayer
instance with the new skeleton JSON and atlas files. This approach ensures that you are using a single WebGL context efficiently.Consider Using
spine-webgl
: If you need more control over rendering and performance, consider usingspine-webgl
directly. This runtime allows you to manage multiple skeletons within a single WebGL context, which can be more efficient than using multipleSpinePlayer
instances.Optimize for Mobile: Be mindful of the number of WebGL contexts and resources used, as mobile devices have limitations. Ensure that you are not exceeding these limits by managing your resources carefully.
By following these steps, you can switch between different skeletons using a single WebGL instance while maintaining good performance on mobile devices.
The Spine Player is not designed to handle on-the-fly changes to the displayed skeleton without disposing of the player.
The easiest solution is to replace the current spine player. Have a look at this example.
Just pass the assets location to the createPlayer
function.
Does this solution fits your needs?
Davide thank you answer, i actually use that solution in my project, people click switch buttom, make player dispose and initialization frequently, in mobiel web side,it make my phone so hot, I wonder if there is a problem with content leakage, can i re-implementation with spine-webgl avoid this performance issue.i want some high performance practice
The dispose function actually disposes everything was initialized by the player. If there was a memory leak, the result would be more likely a page crash.
Can you link or share your project so that I can have a look at your setup? If you don't want to share it publicly, you can send it to contact@esotericsoftware.com.
The spine player sits into the given HTMLElement
and no overflow should happen. If it overflows, maybe there something wrong with your setup.
You shouldn't look at the size of what's inside the webgl canvas since it depends on the devicePixelRatio
.
Unfortunately, you can't achieve that with the spine-player
. You could modify the code and get that result, but it might not be the easier thing to do. If you want to try that, you have to modify spine-webgl
since spine-player
uses it.
This might be a interesting use case for our work in progress spine-widget
. It basically uses a single webgl context to render multiple skeletons. And you can clip the viewport at your desired bounds.
You can give it a try by switching to the ts-webgl-overlay
branch of our repository and learn how to use it launching the webcomponent-tutorial example.
Davide
So I really need to learn spine-webgl, which can help me understand the basic logic of the entire runtime. I am curious about whether spine-play has done performance test on mobile terminals. When drawing animations close to the full screen, the hot phenomenon makes me worry that old mobile phones cannot be well compatible (thank you answer again)
As mentioned yesterday, you can get it by switching to the ts-webgl-overlay
. Then you can build it by yourseld. Its source is in the spine-webgl
folder right now.
But I suggest you to just directly download the library from the page I linked yesterday.