当前位置:网站首页>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);
边栏推荐
- 安恒堡垒机如何启用Radius双因素/双因子(2FA)身份认证
- 缓冲区溢出保护
- 回归测试的分类
- Today's sleep quality record 78 points
- The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
- Wechat applet - Advanced chapter component packaging - Implementation of icon component (I)
- Leetcode——236. The nearest common ancestor of binary tree
- Summary on adding content of background dynamic template builder usage
- Instructions d'utilisation de la trousse de développement du module d'acquisition d'accord du testeur mictr01
- MRS离线数据分析:通过Flink作业处理OBS数据
猜你喜欢

C 6.0 language specification approved

STM32CubeMX,68套组件,遵循10条开源协议

Full details of efficientnet model

电脑Win7系统桌面图标太大怎么调小

Introduction and use of Kitti dataset

Data connection mode in low code platform (Part 2)

Base64 encoding

GAN发明者Ian Goodfellow正式加入DeepMind,任Research Scientist

Huawei cloud database DDS products are deeply enabled

云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
随机推荐
Search engine interface
Summary on adding content of background dynamic template builder usage
Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
GAN发明者Ian Goodfellow正式加入DeepMind,任Research Scientist
ES日志报错赏析-- allow delete
一款你不容错过的Laravel后台管理扩展包 —— Voyager
数据库如何进行动态自定义排序?
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...
Es log error appreciation -trying to create too many buckets
昇腾体验官第五期随手记I
Differences between cookies and sessions
寺岗电子称修改IP简易步骤
Leetcode——剑指 Offer 05. 替换空格
Simple steps for modifying IP of sigang electronic scale
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
小米的芯片自研之路
Decrypt the three dimensional design of the game
比尔·盖茨晒48年前简历:“没你们的好看”
LeetCode每日一题(636. Exclusive Time of Functions)
OAuth 2.0 + JWT protect API security