cocos2dx3.2 spine动画
程序员文章站
2022-03-13 13:48:40
...
首先提供spine的最新运行库,当然这不是官方的,里面封装了ffd,是我自己修改过并添加了ffd代码,采用newSkeletonAnimation区别原先的skeletonAnimation具体点击:spine FFD runtime
其中要注意的几个地方:
1. 1.8版本以上的atlas做了修改 在第二行添加了size 所以只要删除size这一行即可,
2. 动作制作的时候如果层级有发生改变或者切换了skin,slot,请K帧一下,修改的部分:draworder和bone,一般首尾都K一下就行了。
3.至于.skel的binary文件,是spine本身就提供的二进制文件,性能必然高于json,本人目前正在修改完善spine runtime的binary(因为官方也不提供,完成起来慢了点,以后或许会放出)。
4.newskeletonanimation在create时候最后一个参数scale别忘了。
说一下runtime中常用的一些方法:
skeletonNode = NEWSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas", 0.6f);//创建动作,最后的参数为scale.
skeletonNode->startListener = [this] (int trackIndex) {//设置动作开始检测的监听器
spTrackEntry* entry = spAnimationState_getCurrent(skeletonNode->state, trackIndex);//获得当前动作的状态信息
const char* animationName = (entry && entry->animation) ? entry->animation->name : 0;
log("%d start: %s", trackIndex, animationName);
};
skeletonNode->endListener = [] (int trackIndex) {//同理,结束动作监听
log("%d end", trackIndex);
};
skeletonNode->completeListener = [] (int trackIndex, int loopCount) {//同理,完成动作监听
log("%d complete: %d", trackIndex, loopCount);
};
skeletonNode->eventListener = [] (int trackIndex, spEvent* event) {//同理,事件监听,在spine中编辑好event导出
log("%d event: %s, %d, %f, %s", trackIndex, event->data->name, event->intValue, event->floatValue, event->stringValue);
};
skeletonNode->setMix("walk", "jump", 0.2f);//协调动作
skeletonNode->setMix("jump", "run", 0.2f);
skeletonNode->setAnimation(0, "walk", true);//设置动作,可用多个set进行动作混合
spTrackEntry* jumpEntry = skeletonNode->addAnimation(0, "jump", false, 3);//添加动作,在上个动作直接玩之后,之后为循环参数和delay
skeletonNode->addAnimation(0, "run", true);
skeletonNode->setStartListener(jumpEntry, [] (int trackIndex) {
log("jumped!");
});
skeletonNode->timeScale = 0.3f;//动作间隔
skeletonNode->debugBones = true;//debug模式
skeletonNode->update(0);//更新动作
spBone* root=skeletonNode->findBone("root");//找到name为root的骨骼,同理 通过 findslot 可以找到名字为name的slot
NEWSkeletonAnimation* skeletonNode;
skeletonNode = NEWSkeletonAnimation::createWithFile("Maid.json", "Maid.atlas", 0.6f);
skeletonNode->startListener = [this] (int trackIndex) {
spTrackEntry* entry = spAnimationState_getCurrent(skeletonNode->state, trackIndex);
const char* animationName = (entry && entry->animation) ? entry->animation->name : 0;
log("%d start: %s", trackIndex, animationName);
};
skeletonNode->endListener = [=] (int trackIndex) {
log("%d end", trackIndex);
m_isSkeletonSiwtch = false;
};
skeletonNode->completeListener = [] (int trackIndex, int loopCount) {
log("%d complete: %d", trackIndex, loopCount);
};
skeletonNode->eventListener = [] (int trackIndex, spEvent* event) {
log("%d event: %s, %d, %f, %s", trackIndex, event->data->name, event->intValue, event->floatValue, event->stringValue);
};
skeletonNode->setPosition(100, 100);
this->addChild(skeletonNode);
//skeletonNode->setAnimation(0, "Event", false);
转载于:https://my.oschina.net/ffs/blog/316972
上一篇: 京东app页眉-推荐-页脚制作
下一篇: 商城实战项目