Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

About Spine Data cache

$
0
0

@StanLeung wrote:

Hi All,

I am using 3.10 lib and I am trying to solve a problem about how to cache Spine Data. Right now my idea is to create a global map object as a cache, then in my new game loading screen I preload the SkeletonRenderer into this cache.

	auto skeletonRenderer = SkeletonRenderer::createWithFile("spineboy/spineboy.json", "spineboy/spineboy.atlas", 1);
	_spineCache.insert(std::make_pair("spineboy", skeletonRenderer ));

Well, 2nd step, I suppose I can create SkeletonAnimation from Skeleton data, then I try to get data from SkeletonRenderer.

	auto cacheData = _spineCache.at("spineboy")->getSkeleton()->data;
	auto skeletonNode = SkeletonAnimation::createWithData(cacheData);

Then I setAnimation, setPosition then add to my game world. when I started game, it passed loading session, started with initlial drawing, but it crashed when drawing this spine object.

After that I tried to figure out is that my map object fail to store data. I tried to not use cache, created SkeletonRenderer directly on top of SkeletonAnimation::createWithData and then ran it with the same result...

	auto directRenderer = SkeletonRenderer::createWithFile("spineboy/spineboy.json", "spineboy/spineboy.atlas", 1);
	auto skeletonNode = SkeletonAnimation::createWithData(directRenderer->getSkeleton()->data);

So, question is "Does SkeletonAnimation::createWithData(SkeletonRenderer->getSkeleton()->data) work?"

As there is no problem to draw spine if I use SkeletonAnimation::createWithFile.

	auto skeletonNode = SkeletonAnimation::createWithFile("spineboy/spineboy.json", "spineboy/spineboy.atlas", 1);

Finally, I found that the crash is caused by skeletonNode->setAnimation(0, "walk", true);
But it works fine if my skeletonNode is createWithFile, only failed when it is createWithData. If I remove setAnimation line it still can draw for createWithData without animation...

I do appreciate your help! this problem has already held me up for a few hours.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17070

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>