当前位置:网站首页>Cocoscreator operates spine for animation fusion
Cocoscreator operates spine for animation fusion
2022-07-07 14:42:00 【Snail games】
Animation fusion
When there are multiple animations on a bone , We can use sp.setAnimation() Play animation
however , Use it directly sp.setAnimation() When playing , There will be a problem of rigid animation switching , This kind of trace affects the experience of the game , So based on the spine stay Cocos Medium API We can fuse the two animations
What is animation fusion
As can be seen in the picture Idle and Walking There is overlap between , The red line is the switching action time , The action switching time is between the red and green lines , The animation between them is Idle And Walking Mixing , There will be a smooth transition between these two animations
Fusion code implementation ( Jane , No weight )
First use an animation playback pipeline to play an animation
this.spine_node.setAnimation(0, 'Idle', true);
Here I get Idle The animation time of
getAnimationTimeByName() I inherited it sp.Skeleton Custom methods , Mount in the project spine This inheritance class will be used everywhere
const time = this.spine_node.getAnimationTimeByName('Idle');
/**
* Get animation time
* @param name Animation name
* @returns Return to animation duration s
*/
public getAnimationTimeByName(name: string) {
const state = this.getState();
if (state == undefined) throw `[ERROR SPINE ANIMATION] Unable to get animation status >`;
const { animations } = state.data.skeletonData;
let result = 0;
for (const key in animations) {
if (Object.prototype.hasOwnProperty.call(animations, key)) {
const element = animations[key];
if (element.name == name) {
result = element.duration;
}
}
}
return result;
}
Still play Idle Animated pipeline , Add Walking Animation , And delay two Idle Play after animation time ( Time can be customized , His unit is seconds )
this.spine_node.addAnimation(0, 'Walking', true, time * 2);
The last thing to do is mix , This step is to generate the part between the red and green lines
time It refers to the time between the red and green lines , In this case, it means , stay Idle Mix after the first period of playback Walking Animation , Produce a smooth transition
this.spine_node.setMix('Idle', 'Walking', time);
Complete code
this.spine_node.clearTracks();
this.spine_node.setAnimation(0, 'Idle', true);
const time = this.spine_node.getAnimationTimeByName('Idle');
this.spine_node.addAnimation(0, 'Walking', true, time * 2);
this.spine_node.setMix('Idle', 'Walking', time);
边栏推荐
- How bad can a programmer be? Nima, they are all talents
- 寺岗电子称修改IP简易步骤
- Webrtc audio anti weak network technology (Part 1)
- Multi merchant mall system function disassembly lecture 01 - Product Architecture
- Introduction and use of Kitti dataset
- 解析PHP跳出循环的方法以及continue、break、exit的区别介绍
- 【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
- leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】
- Simple steps for modifying IP of sigang electronic scale
- 多商戶商城系統功能拆解01講-產品架構
猜你喜欢
#yyds干货盘点# 解决名企真题:交叉线
设备故障预测机床故障提前预警机械设备振动监测机床故障预警CNC震动无线监控设备异常提前预警
【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行
Data Lake (IX): Iceberg features and data types
电脑Win7系统桌面图标太大怎么调小
内部排序——插入排序
2022pagc Golden Sail award | rongyun won the "outstanding product technology service provider of the year"
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
Pert diagram (engineering network diagram)
Wechat applet - Advanced chapter component packaging - Implementation of icon component (I)
随机推荐
Data connection mode in low code platform (Part 2)
设备故障预测机床故障提前预警机械设备振动监测机床故障预警CNC震动无线监控设备异常提前预警
「2022年7月」WuKong编辑器更版记录
LeetCode每日一题(636. Exclusive Time of Functions)
Reading and understanding of eventbus source code
Five pain points for big companies to open source
Base64 encoding
PD虚拟机教程:如何在ParallelsDesktop虚拟机中设置可使用的快捷键?
Wechat applet - Advanced chapter component packaging - Implementation of icon component (I)
PyTorch模型训练实战技巧,突破速度瓶颈
寺岗电子称修改IP简易步骤
数据库如何进行动态自定义排序?
EfficientNet模型的完整细节
2022pagc Golden Sail award | rongyun won the "outstanding product technology service provider of the year"
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
Mrs offline data analysis: process OBS data through Flink job
【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行
⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
MRS离线数据分析:通过Flink作业处理OBS数据
今日睡眠质量记录78分