• Editor
  • Loading skeleton with skins (spine-cocos2d-x)

I copied goblin's atlases, images and skeletons from libgdx runtime example to cocos2dx example. Now I am getting error when loading skins from goblins skeleton file.
I would be very appreciated if you check it out.

Maybe, I am doing something wrong? Maybe I need to set up default skin before loading skeleton?

Related Discussions
...

Fixed, sorry about that. Example here:
https://github.com/EsotericSoftware/spi ... n.cpp#L106
A couple things:

  • When you set the skin it attaches all attachments that were attached from the old skin (see Skin_attachAll). However you just created the skeleton so there was no old skin, meaning your skeleton will only have attachments from the default skin, not those from the skin you just set. You must call setSlotsToBindPose or setToBindPose after setting the skin initially.

  • If you use setToBindPose it will reset the root bone position, so be sure to set that position after setToBindPose. You will be very confused otherwise!

It works fine now, thanks. However, it is a bit inconvenient to call Skeleton_setSkinByName, Skeleton_setSlotsToBindPose and Skeleton_setAttachment from my code. I think that adding those methods for CCSkeleton would be a better solution.

I will add Skeleton methods to CCSkeleton. Anything else you want to do you'll have to use the C API though, can't wrap the whole thing. 🙂

한 달 후

Ack, not all of my random options of sprites have skins. But accessing the skinCount helped me set the inner-random-random.

CCRect r = boundingBox();
_spine = new CCSkeletonAnimation((shapename+".json").c_str(), "creatures.atlas");
int count = _spine->skeleton->data->skinCount;
if (_spine->skeleton->data->skinCount) {
    Skeleton_setSkin(_spine->skeleton, _spine->skeleton->data->skins[rand()%count]);
    _spine->setSlotsToSetupPose();
}
_spine->timeScale = 1.f;
_spine->setPosition( ccp(r.size.width * 0.5f, r.size.height * 0.5f) );
_spine->setAnimation("idle", true);
addChild(_spine);