当前位置:网站首页>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);
边栏推荐
- The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
- 《微信小程序-进阶篇》组件封装-Icon组件的实现(一)
- AWS learning notes (III)
- What is cloud primordial? This time, I can finally understand!
- Leetcode——剑指 Offer 05. 替换空格
- Substance Painter筆記:多顯示器且多分辨率顯示器時的設置
- OAuth 2.0 + JWT 保护API安全
- Search engine interface
- Small game design framework
- Mlgo: Google AI releases industrial compiler optimized machine learning framework
猜你喜欢
什么是云原生?这回终于能搞明白了!
"July 2022" Wukong editor update record
#yyds干货盘点# 解决名企真题:交叉线
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
Introduction and use of Kitti dataset
2022pagc Golden Sail award | rongyun won the "outstanding product technology service provider of the year"
Démontage de la fonction du système multi - Merchant Mall 01 - architecture du produit
多商户商城系统功能拆解01讲-产品架构
Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
在软件工程领域,搞科研的这十年!
随机推荐
Docker deploy Oracle
在软件工程领域,搞科研的这十年!
PG基础篇--逻辑结构管理(锁机制--表锁)
EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
Hangdian oj2092 integer solution
CVPR2022 | 医学图像分析中基于频率注入的后门攻击
Demis Hassabis谈AlphaFold未来目标
Substance Painter笔记:多显示器且多分辨率显示器时的设置
全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
#yyds干货盘点# 解决名企真题:交叉线
Cascading update with Oracle trigger
小程序目录结构
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
PAG体验:十分钟完成AE动效部署上线各平台!
Hangdian oj2054 a = = B? ???
How bad can a programmer be? Nima, they are all talents
【愚公系列】2022年7月 Go教学课程 005-变量
PAG experience: complete AE dynamic deployment and launch all platforms in ten minutes!
低代码平台中的数据连接方式(下)