Cocos实例4:使用Spine动画的渲染模式以及更改颜色的案例
创作时间:
作者:
@小白创作中心
Cocos实例4:使用Spine动画的渲染模式以及更改颜色的案例
引用
CSDN
1.
https://blog.csdn.net/qq_43242691/article/details/137349335
本文将介绍如何在Cocos Creator中使用Spine动画的渲染模式以及如何更改动画的颜色。通过具体的代码示例,读者可以学习到如何切换Spine动画的渲染模式(实时模式和缓存模式),以及如何动态更改动画的颜色。
使用Spine动画的渲染模式以及更改颜色的案例
关于Spine动画的渲染模式和颜色属性描述可参考:CocosCtreator知识点5:2D渲染组件Spine Skeleton详解
源码:
import { _decorator, Color, Component, Label, Node, sp } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Test')
export class Test extends Component {
@property({ type: Label })
runMode: Label = null!;
@property({ type: Label })
tip: Label = null!;
start() {
}
onChangeModel(){
const skelComp = this.node.getComponent(sp.Skeleton);
if (skelComp!.isAnimationCached()) {
skelComp!.setAnimationCacheMode(sp.AnimationCacheMode.REALTIME);
this.runMode.string = 'model:realtime';
try {
let ep = skelComp!.setAnimation(0,"walk",false);
skelComp!.setTrackCompleteListener(ep,()=>{
console.log('walk event complete');
this.tip.string = 'walk event complete';
})
} catch (error) {
console.log(error);
this.tip.string = error;
}
} else {
skelComp!.setAnimationCacheMode(sp.AnimationCacheMode.PRIVATE_CACHE);
this.runMode.string = 'model:cache';
try {
let ep = skelComp!.setAnimation(0,"walk",false);
skelComp!.setTrackCompleteListener(ep,()=>{
console.log('walk event complete');
this.tip.string = 'walk event complete';
})
} catch (error) {
console.log(error);
this.tip.string = error;
}
}
}
private colorCount = 0;
onChangeColor(){
const skelComp = this.node.getComponent(sp.Skeleton);
if (this.colorCount === 0) {
skelComp!.color = new Color(255, 255, 0, 255);
} else if (this.colorCount === 1) {
skelComp!.color = new Color(0, 0, 255, 150);
} else {
skelComp!.color = new Color(179, 245, 170, 255);
}
this.colorCount++;
this.colorCount = this.colorCount % 3;
}
update(deltaTime: number) {
}
}
效果:
热门推荐
幼儿园团队建设与管理怎么开始?
洛宁体育中心项目:安全管理的“蜕变”
图片排列艺术:让你的PPT更加吸引眼球
如何选择合适的黄金购买渠道?这些渠道有哪些优缺点?
去美元化悄悄进行了十年,市场选择了黄金!
英短蓝猫的优缺点分析,适合新手饲养吗?
思安“源网荷储一体化”技术领跑工业低碳转型
第1现场|缅甸余震不断,人力物力严重不足,呼吁国际救援
春笋炒腊肉三步去涩技巧,鲜嫩不翻车秘诀公开
西班牙黄金时代:一个影响世界的辉煌时期
中国广电发布5G手机白皮书:3500元以上手机必选支持n79频段
在家制作地瓜干的简单方法与技巧
KPI在促进员工个人成长中的角色
如何分析黄金价格的实时变化?这种实时变化如何反映市场动态?
榴莲控必备!超赞的榴莲美食大推荐
高速匝道超速后如何处理?这种处理方式有什么依据?
小腿按摩手法图解:四种简单实用的按摩方法
厨房柜台面板用什么好?四种主流材质全面解析
岩板简介以及和人造石、石英石的物理性质对比
哪吒的黑眼圈是怎么形成的?
悬疑神作《白夜行》:读透人性复杂,感悟世间冷暖!
如何合理租房?租房时需要注意哪些事项?
高血压管理中的智能化监控与数据分析应用探索
电子信息工程技术专业详解:培养目标、就业方向与核心课程
价格管控流程透明度:从标准制定到系统实施的全方位指南
蓝莓的种植与适应环境(了解蓝莓的适宜环境与种植技巧,助你打造蓝莓园)
养殖栀子花的配土方法,可将相同比例的泥炭土和沙壤土混合使用
房屋漏水维修价格预算及漏水检测服务标准
溯源中国小百科 | 阿胶品种考:驴皮是如何胜出的?
数据库建模如何分析图形