123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { CCString, Color, Component, sp, _decorator} from 'cc';
- const { ccclass, property } = _decorator;
- /**
- * spine动画表现管理
- * @author
- */
- @ccclass('UISpineMovie')
- export default class UISpineMovie extends Component {
- @property({ type: [CCString], displayName: '动画列表' })
- private animat_names: Array<string> = [];
- @property({type: sp.Skeleton, tooltip: '角色动画' })
- private spine:sp.Skeleton = null!;
- private cur:string =null!;
- private index:number=0;
- onLoad() {
-
- }
- start(){
- //this.spine.clearTracks()
- /*this.spine.setStartListener(function(){
- console.log("动画开始")
- }.bind(this));*/
- /* this.spine.setEventListener(((trackEntry:any, event:any) => {
- //var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- //console.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
- this.unit.DoEvent(event.data.name);
- }) as any);*/
- //
- //let duration = this.spine.getCurrent(0).animation.duration;
- //let frames = Math.ceil(frameRate * duration);
- //let secondsPerFrame = 1 / frameRate;
- //`总帧数 ${this.frames}`;
- //this.spine.setCompleteListener(trackEntry => {
- //});
-
- if(this.animat_names.length>0){
- this.index=0;
- if(this.index==this.animat_names.length-1){
- this.DoAnimation(this.animat_names[this.index],true);
- }else{
- this.DoAnimation(this.animat_names[this.index],false);
- }
- this.spine.setCompleteListener(function(){
- this.index++;
- if(this.index<this.animat_names.length){
- if(this.index==this.animat_names.length-1){
- this.DoAnimation(this.animat_names[this.index],true);
- }else{
- this.DoAnimation(this.animat_names[this.index],false);
- }
- }else{
- this.spine.setCompleteListener(null);
- }
- }.bind(this));
- }
- }
- public SetSkin(skin:string):void{
- this.spine.setSkin(skin);
- }
- public DoAnimation(animation:string,loop:boolean=true,track:number=0,force:boolean=false){
- if(force){
- this.spine.setAnimation(track,animation,loop);
- return;
- }
- if(this.cur==animation)return;
- this.spine.setAnimation(track,animation,loop);
- }
- /**设置是否暂停 */
- public SetPaused(paused:boolean):void{
- this.spine.paused=paused;
- }
- /**获取是否暂停 */
- public GetPaused():boolean{
- return this.spine.paused;
- }
- public CheckPaused(paused:boolean):void{
- if(this.spine.paused!=paused)this.spine.paused=paused;
- }
- /** 闪色表现 Color.RED 0.1*/
- public Flash(color:Color,time:number,reColor:Color=Color.WHITE):void{
- if(this.spine.color!=color){
- this.spine.color=color;
- this.unscheduleAllCallbacks();
- this.scheduleOnce(()=>{
- this.spine.color = reColor;
- },time);
- }
- }
- /**
- * 缩放动画播放速率
- * @override
- * @param scale 缩放倍率
- */
- public scaleTime(scale: number) {
- if (scale > 0)
- this.spine.timeScale = scale;
- }
- public getBone(name: string): any {
- var bone = this.spine.findBone(name);
- return bone
- }
- }
|